1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <set> #include <iomanip> #include <algorithm> #include <queue> #include <map> #include <string> #define INF 0x3f3f3f3f #define rep(i,a,n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=n-1;i>=a;i--) using namespace std; typedef long long ll; const double eps =1e-10; const int maxn=50; int n;
int dcmp(double x){ if(fabs(x)<eps) return 0; else return x<0?-1:1; }
class Point{ public: ll x,y; Point (ll x=0,ll y=0):x(x),y(y){} };
typedef Point Vector;
Vector operator + (const Vector &A,const Vector &B) { return Vector(A.x+B.x,A.y+B.y); }
Vector operator - (const Vector &A,const Vector &B) { return Vector(A.x-B.x,A.y-B.y); }
Vector operator * (const Vector &A,double p) { return Vector(A.x*p,A.y*p); }
Vector operator / (const Vector &A,double p) { return Vector(A.x/p,A.y/p); }
double operator * (const Vector &A,const Vector &B) { return A.x*B.x+A.y*B.y; } double dot(const Vector &A,const Vector &B){ return A.x*B.x+A.y*B.y; }
double operator ^ (const Vector &A,const Vector &B){ return A.x*B.y-A.y*B.x; } ll cross(const Vector &A,const Vector &B){ return A.x*B.y-A.y*B.x; }
double abs(const Vector &A){ return sqrt(dot(A,A));}
double area2(const Point &A,const Point &B,const Point &C){ return cross(B-A,C-A) ;}
bool operator < (const Point &A,const Point &B) { return A.x==B.x?A.y<B.y:A.x<B.x; }
bool operator == (const Point &A,const Point &B) { return dcmp(A.x-B.x)==0&& dcmp(A.y-B.y)==0; }
Vector rotate(Vector A,double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}
Vector normal(Vector A){ double l=abs(A); return Vector(-A.y/l,A.x/l); }
class Line { public: Point s,e; Line(){} Line(Point _s,Point _e){ s=_s;e=_e; } }line[maxn];
bool inter(Line l1,Line l2){
return ( max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x) && max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x) && max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y) && max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y) && dcmp((l2.s-l1.s)^(l1.s-l1.e))*dcmp((l2.e-l1.s)^(l1.s-l1.e))<0 && dcmp((l1.s-l2.s)^(l2.s-l2.e))*dcmp((l1.e-l2.s)^(l2.s-l2.e))<0 ) ; } bool inter(Point a1,Point a2,Point b1,Point b2){ Line l1(a1,a2),l2(b1,b2); return inter(l1,l2); }
Point getinter(Line l1,Line l2){ Vector v=l1.s-l1.e; Vector w=l2.s-l2.e; Vector u=l1.e-l2.e; double t=cross(w,u)/cross(v,w); return l1.e+v*t; } Point getinter(Point a1,Point a2,Point b1,Point b2){ Line l1(a1,a2); Line l2(b1,b2); return getinter(l1,l2); }
int online(Point a,Line l){ if(dcmp(cross(l.s-a,l.e-a))!=0) return 0; double pans=dcmp(dot(l.s-a,l.e-a));
if(pans<0) return 1; else if(pans==0) return 2; else if(pans>0) return 3; } int online(Point a,Point b1,Point b2){ Line l(b1,b2); return online(a,l); } int main(){ int t; cin>>t; while(t--){ Point pnow(0,0),pnext(0,0); ll area=0; string s; cin>>s; int len=s.size(); rep(i,0,len){ pnow=pnext; switch(s[i]){ case '8': pnext.y++; break; case '2': pnext.y--; break; case '6': pnext.x++; break; case '4': pnext.x--; break; case '9': pnext.x++, pnext.y++; break; case '7': pnext.x--, pnext.y++; break; case '3': pnext.x++, pnext.y--; break; case '1': pnext.x--, pnext.y--; break; default: break;
} area+=cross(pnext,pnow); } area=(area<0?(0-area):area); if(area%2==0) cout<<area/2<<endl; else cout<<area/2<<".5"<<endl; } }
|