HDU 1392 Surround the Trees
来源:互联网 发布:卡佩拉毒蛇队数据 编辑:程序博客网 时间:2024/06/05 09:00
平面凸包
不过注意下两个点的时候 只输出距离就可以了 我也不知道为什么 没读懂题意 英文捉急!
#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;struct H{ int x,y;}a[1010];int team1[1010],team2[1010],top1,top2;int CHA(H a,H b,H c){ int x1=b.x-a.x; int y1=b.y-a.y; int x2=c.x-b.x; int y2=c.y-b.y; return x1*y2-x2*y1;}double D(H a,H b){ double y=a.y-b.y; double x=a.x-b.x; return sqrt(y*y+x*x);}bool cmp(H a, H b){ if(a.x!=b.x) return a.x<b.x; return a.y<b.y;}int main(){// freopen("a.in","r",stdin);// freopen("wa.out","w",stdout); int n; while(scanf("%d",&n)&&n!=0) { for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } if(n==1) { printf("0.00\n"); continue; } if(n==2) { printf("%.2f\n",D(a[1],a[2])); continue; } // cout<<"faf"; sort(a+1,a+n+1,cmp); top1=top2=0; for(int i=1;i<=n;i++) { while(a[i].x==a[i+1].x&&i+1<=n) { i++; } while(top1!=1&&top1!=0&&CHA(a[team1[top1-1]],a[team1[top1]],a[i])>=0) top1--; team1[++top1]=i; } for(int i=1;i<=n;i++) { while(top2!=1&&top2!=0&&CHA(a[team2[top2-1]],a[team2[top2]],a[i])<=0) top2--; team2[++top2]=i; while(a[i].x==a[i+1].x&&i+1<=n) { i++; } } double ans=0; for(int i=1;i<top1;i++) ans+=D(a[team1[i]],a[team1[i+1]]); for(int i=1;i<top2;i++) ans+=D(a[team2[i]],a[team2[i+1]]); ans+=D(a[team2[1]],a[team1[1]]); ans+=D(a[team2[top2]],a[team1[top1]]); printf("%.2f\n",ans); } return 0;}
0 0
- HDU 1392 Surround the Trees
- HDU 1392 Surround the Trees
- hdu 1392 Surround the Trees
- HDU 1392 Surround the Trees
- HDU 1392 Surround the Trees
- hdu 1392 Surround the Trees
- hdu 1392 Surround the Trees
- HDU 1392 Surround the Trees
- hdu 1392 Surround the Trees
- hdu 1392 Surround the Trees
- Surround the Trees(hdu 1392)
- hdu 1392 Surround the Trees
- HDU - 1392 Surround the Trees
- HDU 1392 Surround the Trees
- hdu 1392 Surround the Trees
- HDU 1392 Surround the Trees
- Surround the Trees HDU
- HDU 1392 Surround the Trees(凸包)
- PAT (Advanced Level) Practise 1048 Find Coins (25)
- PreparedStatement动态给数据库写内容 以及之前数据库崩了的事情
- Linux 内核中的 kconfig 原理
- spring的lib下面的jar包与UserLibarayjar包造成的类找不到异常
- 【读书笔记】CSS3学习(一)
- HDU 1392 Surround the Trees
- POJ 2553 The Bottom of a Graph 强连通分量
- iOS开发之Swift标签栏按钮UITabBarItem样式修改(图标文字尺寸,颜色等)
- iOS开发之详解正则表达式
- oc之id 总结思考
- fragmenTransaction和fragment生命周期
- Fragment overlap problem
- Android Support Design Library - CoordinatorLayout
- unity3D中使用Socket进行数据通信(三)