zoukankan      html  css  js  c++  java
  • poj 1113

    凸包

    至今还不知道这道题为什么凸包就是解,在网上搜结题报告也都是说求凸包,没告诉深层原因,求大神解答

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <math.h>
    using namespace std;
    const int maxn=1000+10;
    struct node
    {
    	int x,y;
    };
    node point[maxn];
    int ch[maxn];
    int n,l;
    bool cmp(node a,node b)
    {
    	if(a.x<b.x) return true;
    	else if(a.x==b.x) return a.y<b.y?true:false;
    	else return false;
    }
    int cross(node a,node b,node c)
    {
    	return (b.x-a.x)*(c.y-b.y)-(b.y-a.y)*(c.x-b.x);
    }
    int  Andrew()
    {
    	sort(point,point+n,cmp);
    	int m=0;
    	int i;
    	for(i=0;i<n;i++)
    	{
    		while(m>1&&cross(point[ch[m-1]],point[ch[m-2]],point[i])<=0) m--;
    		ch[m++]=i;
    	}
    	int k=m;
    	for(i=n-2;i>=0;i--)
    	{
    		while(m>k&&cross(point[ch[m-1]],point[ch[m-2]],point[i])<=0) m--;
    		ch[m++]=i;
    	}
    	return m;
    }
    double dis(node a,node b)
    {
    	return sqrt(double((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)));
    }
    int main()
    {
    	while(~scanf("%d%d",&n,&l))
    	{
    		int i;
    		for(i=0;i<n;i++) scanf("%d%d",&point[i].x,&point[i].y);
    		int tot=Andrew();
    		double out=2*acos(-1.0)*l;
    		for(i=0;i<tot-1;i++)
    		{
    			out+=dis(point[ch[i]],point[ch[i+1]]);
    		}
    		printf("%.lf\n",out);
    	}
    	return 0;
    }


  • 相关阅读:
    一本通1559跳跳棋
    一本通1558聚会
    一本通1555【例 4】次小生成树
    P1880 [NOI1995]石子合并
    P2066 机器分配
    P2073 送花
    P1886 滑动窗口
    P1637 三元上升子序列
    P1533 可怜的狗狗
    P1631 序列合并
  • 原文地址:https://www.cnblogs.com/lj030/p/3002235.html
Copyright © 2011-2022 走看看