版权声明:仅供研究,转载请注明出处。 https://blog.csdn.net/CSUstudent007/article/details/83473224
思路:
凸包算法,Andrew,坑的一点是int会爆,要用longlong,而且注意没有小数时输出整数。
ps:这个题目其实有点问题,因为没有说明它是凸多边形,如果是凹多边形这么做是无意义的(开始我以为要考虑凹多边形,把算法弄得超级复杂调试了半天也不行)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[10]={0,1,1,1,0,0,0,-1,-1,-1};
int dy[10]={0,-1,0,1,-1,0,1,-1,0,1};
char str[1000000+10];
ll area,x,y,px,py;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
int len = strlen(str);
if(len<3||'5'==str[0])
{
printf("0\n");
continue;
}
area = 0;
x = y = 0;
for(int i=0; i<len-1; i++)
{
px = x+dx[str[i]-'0'];
py = y+dy[str[i]-'0'];
area += (x*py-y*px);
x = px;
y = py;
}
if(area < 0) area = -area;
printf("%lld",area/2);
if(area % 2) printf(".5");
printf("\n");
}
return 0;
}