Area POJ - 1654 

题意: 8个方向,现在用1~8代表8个方向给个字符串s. 求构成多边形的面积

思路:叉积求面积,用long long 存ans ,最后判小数位 . 无论double 还是 long double  无法控制更好的精度.并且这题卡能内存,不能把点都存下来,而是边读入边计算

#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define x  adsfadwsfasdfas
#define sx  dsafasfaseer
#define sy  dsafsfaseer
#define sx  dsafasfaser
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+6;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;

    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
struct Point{
      ll x,y;
      Point(ll x=0.0, ll y=0.0) : x(x), y(y) {}
      Point operator-(const Point &rhs)const{
          return Point(x-rhs.x,y-rhs.y);
      }
};
typedef Point Vector;
ll cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}

char s[N];
int main(void){
    int T;
    sf(T);
    while(T--){
        scanf("%s",s);
        ll x=0,y=0,sx=0,sy=0,ret=0;
        for(int i=0;i<(int)strlen(s)-1;++i){
            int num=s[i]-'0';
            if(num==1) --x,--y;
            else if(num==2) x,--y;
            else if(num==3) ++x,--y;
            else if(num==4) --x,y;
            else if(num==6) ++x,y;
            else if(num==7) --x,++y;
            else if(num==8) x,++y;
            else if(num==9) ++x,++y;
            ret+=cross({x,y},{sx,sy});
            sx=x,sy=y;
        }
        if(ret<0)   ret=-ret;
        printf("%lld",ret/2);
        if(ret&1)   printf(".5\n");
        else    printf("\n");
    }

    return 0;
}