poj-1113
来源:互联网 发布:刷搜狗下拉框软件 编辑:程序博客网 时间:2024/05/18 04:01
凸包,第一次接触。。
无责任,无道德贴个别人的代码。。
#include<iostream>#include<cmath>#include<algorithm>using namespace std;const int MAXN=1008;const double PI=acos(-1.0);struct point{int x;int y;}p[MAXN],que[MAXN]; int top; double dis(point a, point b){return sqrt(double((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));}// 求ca与cb的叉积//叉乘,如果大于0,则说明直线ca在cb的顺时针方向,即ca在cb下面int cross(point a,point b, point c){ return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);}// 用GrahamScan求凸包void GrahamScan(int n){point t;int k=0,i,j;for(i=1;i<n;++i)if(p[i].y < p[k].y || (p[i].y==p[k].y && p[i].x<p[k].x))k=i;t=p[0];p[0]=p[k];p[k]=t;for(i=1;i<n;++i)for(j=i+1;j<n;++j)if(cross(p[j],p[i],p[0])>0 || (cross(p[j], p[i], p[0])==0 && dis(p[0], p[j])<dis(p[0], p[i]))){t=p[i];p[i]=p[j];p[j]=t;}top=-1;que[++top]=p[0];que[++top]=p[1];que[++top]=p[2];for(i=3;i<n;++i) { while((cross(p[i],que[top],que[top-1]))>0) //如果不能左转,则退栈.注意:不能为大于等号 top--; que[++top]=p[i]; }top++;} int main(){//freopen("d:\\test.txt", "r", stdin);int i,n,l;cin>>n>>l;for(i=0;i<n;++i)cin>>p[i].x>>p[i].y;GrahamScan(n);double sum=0;for(i=0;i<top;++i)sum+=dis(que[i],que[(i+1)%top]);sum+=2*PI*l;cout<<(int)(sum+0.5)<<endl;return 0;}
- poj 2365 poj 1113
- poj 1113
- POJ 1113
- poj 1113
- POJ 1113
- poj-1113
- poj 1113
- POJ 1113
- poj 1113
- POJ 1113
- poj 1113
- POJ 1113
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- nyoj-105
- nyoj-95
- nyoj-94
- nyoj-76
- nyoj-77
- poj-1113
- nyoj-78
- nyoj-79
- nyoj-86
- nyoj-26
- nyoj-27
- nyoj-28
- nyoj-29
- nyoj-72