POJ 1654 Area(水题)

题目链接

卡了一下精度和内存。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <cmath>
 5 #include <iostream>
 6 #include <algorithm>
 7 using namespace std;
 8 #define eps 1e-8
 9 #define N 1000001
10 #define LL __int64
11 int a[9] = {-1,0,1,-1,0,1,-1,0,1};
12 int b[9] = {-1,-1,-1,0,0,0,1,1,1};
13 char str[N];
14 LL cross(LL x1,LL y1,LL x2,LL y2)
15 {
16     return x1*y2 - x2*y1;
17 }
18 int main()
19 {
20     int t,len,i;
21     LL x,y,ans,px,py;
22     scanf("%d",&t);
23     while(t--)
24     {
25         scanf("%s",str);
26         len = strlen(str);
27         px = 0;
28         py = 0;
29         ans = 0;
30         for(i = 0;i < len;i ++)
31         {
32             if(str[i] == '5')break;
33             x = px+a[str[i]-'0'-1];
34             y = py+b[str[i]-'0'-1];
35             ans += cross(x,y,px,py);
36             px = x;
37             py = y;
38         }
39         ans += cross(px,py,0,0);
40         if(ans < 0) ans = -ans;
41         if(ans%2 == 0)
42         printf("%I64d
",ans/2);
43         else
44         printf("%I64d.5
",ans/2);
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/naix-x/p/3370824.html