POJ 3348
水题。不过,题意。。呵呵了。。
围一个凸包,求出面积,然后除以50就可以了。
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 | #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MAXN=10500; struct point { int x,y; }p[MAXN]; int n; int ans[MAXN],st[MAXN]; int stop,cnt; bool cmp(point A,point B){ if (A.y<B.y) return true ; else if (A.y==B.y){ if (A.x<B.x) return true ; } return false ; } bool multi(point a, point b, point c){ return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x)>0; } void slove(){ stop=cnt=0; st[stop++]=0; st[stop++]=1; for ( int i=2;i<n;i++){ while (stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])) stop--; st[stop++]=i; } for ( int i=0;i<stop;i++) ans[cnt++]=st[i]; stop=0; st[stop++]=n-1; st[stop++]=n-2; for ( int i=n-3;i>=0;i--){ while (stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])) stop--; st[stop++]=i; } for ( int i=1;i<stop;i++){ ans[cnt++]=st[i]; } } int cross(point a,point b,point c){ return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x); } int main(){ while ( scanf ( "%d" ,&n)!=EOF){ for ( int i=0;i<n;i++) scanf ( "%d%d" ,&p[i].x,&p[i].y); sort(p,p+n,cmp); slove(); double anst=0; // cout<<cnt<<endl; for ( int i=1;i<cnt-2;i++){ anst+=cross(p[ans[i]],p[ans[i+1]],p[ans[0]]); } anst= fabs (anst)/2; // cout<<anst<<endl; printf ( "%d\n" , int (anst/50)); } return 0; } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步