poj 1654 Area
求多边形的面积;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #include<cstring> #include<vector> using namespace std; class Point { public: int x,y; }point[1000024],d[10]; Point Get_point( Point a, int num ) { Point b; b.x = a.x + d[num].x; b.y = a.y + d[num].y; return b; } int multi( Point p1, Point p2 , Point q ) { return ( p1.x - q.x )*( p2.y - q.y ) - ( p2.x - q.x )*( p1.y - q.y ); } void Initial( ) { d[1].x = -1; d[1].y = -1; d[2].x = 0 ; d[2].y = -1; d[3].x = 1 ; d[3].y = -1; d[4].x = -1; d[4].y = 0; d[6].x = 1 ; d[6].y = 0; d[7].x = -1; d[7].y = 1; d[8].x = 0 ; d[8].y = 1; d[9].x = 1 ; d[9].y = 1; }; int main( ) { int n; Initial(); char str[1000024]; while( scanf( "%d",&n )==1 ) { while( n-- ) { int i = 1; scanf( "%s",str + 1 ); point[0].x = 0 ; point[1].y = 0; while( str[i]!='5' ) { point[i] = Get_point( point[i-1] , str[i]-'0' ); i++; } double ans = 0; for( int j = 1 ; j < i -1 ; j++ ) { ans += multi( point[j] ,point[j+1],point[0]); } ans = fabs( ans/2 ); if( fabs(ans - ( long long )ans) < 1.0e-8 ) printf( "%.0f\n",ans ); else printf( "%.1f\n",ans ); } } //system( "pause" ); return 0; }