poj1654

多边形求面积的题目。。

code:

 1 /*
 2   Time:2013-04-06 15:02:38
 3   State:Accepted
 4 */
 5 #include<iostream>
 6 #include<fstream>
 7 #include<cstring>
 8 #include<cstdlib>
 9 #include<cstdio>
10 #include<string>
11 #include<cmath>
12 #include<algorithm>
13 using namespace std;
14 typedef __int64 LL;
15 struct oo{ LL x , y; };
16 int T;
17 oo a, b, c;
18 LL ans;
19 
20 LL work_x(const oo a,const oo b){
21       return b.x*a.y - a.x * b.y;     
22 }
23 
24 void solve(){
25      char c;
26      a.x = a.y = 0;
27      b.x = b.y = 0;
28      ans = 0;
29      scanf("%c", &c);
30      while (scanf("%c", &c) != EOF && c != '5'){
31           if (c == '8'){  a.x = b.x;     a.y = b.y + 1;}
32           if (c == '2'){  a.x = b.x;     a.y = b.y - 1;}
33           if (c == '6'){  a.x = b.x + 1; a.y = b.y;}
34           if (c == '4'){  a.x = b.x - 1; a.y = b.y;}
35           if (c == '9'){  a.x = b.x + 1; a.y = b.y + 1;}
36           if (c == '7'){  a.x = b.x - 1; a.y = b.y + 1;}
37           if (c == '3'){  a.x = b.x + 1; a.y = b.y - 1;}
38           if (c == '1'){  a.x = b.x - 1; a.y = b.y - 1;}
39           ans += work_x(a , b);
40           b = a;
41      }
42      if (ans < 0) ans *= -1;
43      if (ans & 1) printf("%I64d.5\n",ans / 2);
44      else printf("%I64d\n", ans / 2);
45 }
46 
47 int main(){
48      freopen("poj1654.in","r",stdin);
49      freopen("poj1654.out","w",stdout); 
50      scanf("%d",&T);
51      for (int i = 1; i <= T; ++i){
52         solve();    
53      }
54      fclose(stdin); fclose(stdout);
55 }
原文地址:https://www.cnblogs.com/yzcstc/p/3015757.html