题目来源:
http://poj.org/problem?id=1654
代码如下:
typedef long long LL ; const double EPS = 1e-10; const int Max_N = 1000005; char s[Max_N]; int dx[10]={0,-1,0,1,-1,0,1,-1,0,1}; int dy[10]={0,-1,-1,-1,0,0,0,1,1,1}; struct Point { int x,y; }; int xmult(Point p1, Point p2){ return p1.x*p2.y-p1.y*p2.x; } Point p[Max_N]; LL sum; int main(){ int n; scanf("%d",&n); while(n--){ scanf("%s",s); int len=strlen(s); if(len <3) {printf("0 ");continue;} p[0].x=0,p[0].y=0; for(int i=0; i<len; i++){ p[i+1].x=p[i].x+dx[s[i]-'0' ]; p[i+1].y=p[i].y+dy[s[i]-'0' ]; } sum=0; for(int i=0; i<len; i++){ sum+=xmult(p[i],p[i+1]); } if(sum<0) sum=-sum; if(sum & 1) printf("%lld.5 ",sum/2); else printf("%lld ",sum/2); } return 0; }