zoukankan      html  css  js  c++  java
  • POJ 1113

    求凸包,然后加上一个半径为L的圆周就好了。

    因为每到一个凸包的顶点时,需要保持最小间距为L,则多个顶点围起来会有360度。

    在输出时,不要把结果直接转化主INT,因为这个不是四舍五入。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    const int MAXN=1050;
    int n,l;
    
    int st[MAXN],stop,cnt;
    int ans[MAXN];
    
    struct point{
    	int x,y;
    }p[MAXN];
    
    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=0; cnt=0;
    	st[stop++]=0; st[stop++]=1;
    	for(int i=2;i<n;i++){
    		while(stop>1&&multi(p[st[stop-1]],p[i],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[st[stop-1]],p[i],p[st[stop-2]])) stop--;
    		st[stop++]=i;
    	}
    	for(int i=0;i<stop;i++)
    	ans[cnt++]=st[i];
    }
    
    double dist(point a,point b){
    	return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0);
    }
    
    int main(){
    	while(scanf("%d%d",&n,&l)!=EOF){
    		for(int i=0;i<n;i++){
    			scanf("%d%d",&p[i].x,&p[i].y);
    		}
    		sort(p,p+n,cmp);
    		slove();
    		double anl=4*acos(0.0)*l;
    		for(int i=1;i<cnt;i++){
    			anl+=dist(p[ans[i-1]],p[ans[i]]);
    		}
    		printf("%.0lf
    ",anl);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    leetcode 202 Happy Number
    【C++】函数缺省参数的作用
    【C++】类的两种实例化方法
    【C++】const 常引用的用法
    【Ubuntu】使用root账户登录ubuntu
    【Docker】基本命令使用介绍
    【Ajax】PHP中ajax的基本知识点
    【PHP】mysql基本操作整合
    一条命令搞定在VMware中的Ubuntu14.04 64 位安装Docker
    Java泛型初探
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3880392.html
Copyright © 2011-2022 走看看