POJ 1654 Area 多边形面积

注意这题 多边形有凹有凸。

水题。不解释

View Code
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#define lld __int64
using namespace std;

struct point
{
    lld x, y;
}p[1000003];

lld cal(int n, point *p)
{
    int i;
    lld s = 0;
    p[n] = p[0];
    for(i = 0; i < n; i++)
        s +=  p[i].y * p[i+1].x - p[i].x * p[i+1].y;
    return abs(s);
}

lld dir[10][2] = {0, 0, 1, -1, 0, -1, -1, -1, 1, 0, 0, 0, -1, 0, 1, 1, 0, 1, -1, 1};
char str[1000003];

int main()
{
    int i, j, cas;
    scanf("%d", &cas);
    while( cas--)
    {
        p[0].x = 0; p[0].y = 0;
        int num = 0;
        scanf("%s", str);
        char c;
        int len = strlen(str);
        for(i = 0; i < len; i++)
        {
            int k = str[i] - '0';
            if(k == 5) break;
            p[num+1].x = p[num].x + dir[k][0];
            p[num+1].y = p[num].y + dir[k][1];
            num++;
        }
        if(p[num].x == 0 && p[num].y == 0)
        {
            lld ans = cal(num, p);
            if( ans & 1 ) printf("%I64d.5\n", ans/2);
            else printf("%I64d\n", ans/2);
        }
        else printf("0\n");
    }
    return 0;
}
posted @ 2012-09-03 17:00  To be an ACMan  Views(197)  Comments(0)    收藏  举报