POJ 1654 Area 凸包面积
水题直接码...
/********************* Template ************************/ #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define EPS 1e-8 #define MAXN (int)1e5+50 #define MOD (int)1e9+7 #define PI acos(-1.0) #define LINF ((1LL)<<50) #define INF (1<<30); #define max(a,b) ((a) > (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) #define max3(a,b,c) (max(max(a,b),c)) #define min3(a,b,c) (min(min(a,b),c)) #define BUG cout<<"BUG! "<<endl #define LINE cout<<"--------------"<<endl #define L(t) (t << 1) #define R(t) (t << 1 | 1) #define Mid(a,b) ((a + b) >> 1) #define lowbit(a) (a & -a) #define FIN freopen("in.txt","r",stdin) #define FOUT freopen("out.txt","w",stdout) #pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL; // typedef unsigned long long ULL; typedef __int64 LL; // typedef unisigned __int64 ULL; // int gcd(int a,int b){ return b?gcd(b,a%b):a; } // int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/ struct POINT{ double x,y; POINT(double _x = 0, double _y = 0):x(_x),y(_y){}; void show(){ cout<<x<<" "<<y<<endl; } }p[MAXN]; double dist(POINT p1,POINT p2){ return(sqrt((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y))); } double multiply(POINT sp,POINT ep,POINT op){ return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y); } bool ptcmp(POINT a,POINT b){ if(multiply(a,b,p[0]) == 0) return dist(p[0],a) < dist(p[0],b); return (multiply(a,b,p[0]) > 0); } double Triangle_area(POINT a,POINT b,POINT c){ return multiply(a,b,c)/2; } char a[1000005]; double ax[10] = {0,-1,0,1,-1,0,1,-1,0,1}; double ay[10] = {0,-1,-1,-1,0,0,0,1,1,1}; int main() { //FIN; //FOUT; int T; scanf("%d",&T); getchar(); while(T--){ gets(a); int len = strlen(a); double ans = 0; POINT st = POINT(0,0); for(int i = 0 ; i < len-2 ; i++){ POINT st1 = POINT(st.x+ax[a[i]-'0'],st.y+ay[a[i]-'0']); POINT st2 = POINT(st1.x+ax[a[i+1]-'0'],st1.y+ay[a[i+1]-'0']); ans += Triangle_area(POINT(0,0),st1,st2); st = st1; } ans = fabs(ans); printf("%I64d",LL(ans)); if((ans - floor(ans)) >= EPS) printf(".5\n"); else printf("\n"); } return 0; }