Surround the Trees HDU
来源:互联网 发布:多益网络客服电话 编辑:程序博客网 时间:2024/06/10 07:30
这题小trick在于n=2是不能乘2的,也就是只算两点距离
看你怎么理解凸包吧。。
//#include<bits/stdc++.h> //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<algorithm> #include<queue> #include<string.h> #include<iostream> #include<math.h> #include<set> #include<map> #include<vector> #include<iomanip> using namespace std; const double pi=acos(-1.0); #define ll long long #define pb push_back#define sqr(a) ((a)*(a))#define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))const double eps=1e-6;const int maxn=1e3+56;const int inf=0x3f3f3f3f;int n;int tot;//凸包上点数struct Point{double x,y;Point(){}Point(double x,double y):x(x),y(y){}}point[maxn],vertex[maxn];bool cmp(Point a,Point b){return(a.y<b.y||(a.y== b.y && a.x<b.x));}double xmult(Point p1,Point p2,Point p3){//p3p1,p3p2的夹角测试return ( (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x) );}//正表示p1在p2的顺时针方向int Andrew(){//返回凸包顶点数sort(point,point+n,cmp);int top=1;vertex[0]=point[0];vertex[1]=point[1];for(int i=2;i<n;i++){while(top && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}int len=top;vertex[++top]=point[n-2];for(int i=n-3;i>=0;i--){while(top!=len && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}return top;}int main(){while(~scanf("%d",&n) && n){for(int i=0;i<n;i++){scanf("%lf%lf",&point[i].x,&point[i].y);}if(n==1){puts("0.00");continue;}int tot=Andrew();double ans=0;for(int i=0;i<tot;i++){ans+=dis(vertex[i],vertex[(i+1)%tot]);}if(n==2)ans/=2.0;printf("%.2lf\n",ans);}}
阅读全文
0 0
- Surround the Trees HDU
- 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
- HDU 1392 Surround the Trees(凸包)
- Android TV 官方教程简读1-Building Apps for TV
- Linux打包免安装的Qt程序
- 扑克牌顺子
- sharding-jdbc分库分表规则(2)-多表查询
- day1对象
- Surround the Trees HDU
- Gitolite + repo 搭建安卓源码开发环境
- 翻转单词顺序列
- 使用python在Window10下配置tensorflow
- Codeforces Round #436 (Div. 2) E
- 左旋转字符串
- SpringMVC简例HelloWorld~
- Linux C编程 GCC的使用
- Visual Studio Enterprise 2017 ReferenceManagerPackage的解决方案