标签:有用 long math struct ext typedef pre for col
题目描述:
题解:
本以为是水题结果是神题
计算几何求多边形面积。
考虑到结果一定是整数或者整数/2,我们应该用long long 来存……
用double会死……
还有日常只能用c++编译器,不能用g++。
还有用abs会莫名ce,要手写。
代码:
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; struct Point { ll x,y; Point(){} Point(ll x,ll y):x(x),y(y){} Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);} Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);} ll operator ^ (const Point&a)const{return x*a.y-y*a.x;} }p[10]; typedef Point Vector; int T; char ch[1000050]; void init() { p[1] = Point(-1,-1),p[2] = Point(0,-1),p[3] = Point(1,-1),p[4] = Point(-1,0); p[6] = Point(1,0),p[7] = Point(-1,1),p[8] = Point(0,1),p[9] = Point(1,1); } void work() { scanf("%s",ch+1); Point s0(0,0),s1(0,0),s2(0,0); int len = strlen(ch+1); long long ans = 0; for(int i=1;i<len;i++) { s1 = s2,s2 = s2+p[ch[i]-‘0‘]; ans+=((s1-s0)^(s2-s0)); } if(ans<0)ans=-ans; if(ans&1) { printf("%lld.5\n",ans/2); }else { printf("%lld\n",ans/2); } } int main() { scanf("%d",&T);init(); while(T--)work(); return 0; }
标签:有用 long math struct ext typedef pre for col
原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10983095.html