zoukankan      html  css  js  c++  java
  • 【UVA1303】Wall(凸包)

    点此看题面

    大致题意: 给你一个多边形,要求建一面墙使得墙上的点至少离多边形每个顶点(R)的距离,求最短的墙长。

    考虑(R=0)

    考虑当(R=0)时,所求的答案显然就是求得的凸包的周长。

    因为这堵墙如果向内凹,显然长度只会变大。

    考虑所有情况

    对于任一情况,我们可以得图如下:

    可以发现,答案是绿色部分+紫色部分,而绿色部分=红色部分=凸包周长,紫色部分=圆的周长。

    所以答案就是凸包周长+圆的周长,看起来是不是很简单?

    代码

    #include<bits/stdc++.h>
    #define Tp template<typename Ty>
    #define Ts template<typename Ty,typename... Ar>
    #define Reg register
    #define RI Reg int
    #define Con const
    #define CI Con int&
    #define I inline
    #define W while
    #define N 1000
    using namespace std;
    int n,m;const double pi=acos(-1);
    struct Point
    {
    	int x,y;I Point(CI a=0,CI b=0):x(a),y(b){}
    	I Point operator - (Con Point& o) Con {return Point(x-o.x,y-o.y);}
    	I int operator ^ (Con Point& o) Con {return x*o.y-y*o.x;}
    	I bool operator < (Con Point& o) Con {return x^o.x?x<o.x:y<o.y;}
    	I double len() {return sqrt(x*x+y*y);}
    }p[N+5];
    struct ConvexHull
    {
    	int n;Point p[N+5];I ConvexHull() {n=0;}
    };
    class FastIO
    {
    	private:
    		#define FS 100000
    		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
    		#define tn (x<<3)+(x<<1)
    		#define D isdigit(c=tc())
    		int f;char c,*A,*B,FI[FS];
    	public:
    		I FastIO() {A=B=FI;}
    		Tp I void read(Ty& x) {x=0,f=1;W(!D) f=c^'-'?1:-1;W(x=tn+(c&15),D);x*=f;}
    		Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);}
    }F;
    I ConvexHull GetConvexHull(CI n,Point *p)//求凸包
    {
    	RI i,t;ConvexHull res;
    	for(sort(p+1,p+n+1),i=1;i<=n;++i)//排序,正着扫一遍
    	{
    		W(res.n>1&&((res.p[res.n]-res.p[res.n-1])^(p[i]-res.p[res.n-1]))<=0) --res.n;
    		res.p[++res.n]=p[i];
    	}
    	for(t=res.n,i=n-1;i;--i)//倒着扫一遍
    	{
    		W(res.n>t&&((res.p[res.n]-res.p[res.n-1])^(p[i]-res.p[res.n-1]))<=0) --res.n;
    		res.p[++res.n]=p[i];
    	}return res;//返回结果
    }
    I double PolygonC(Con ConvexHull& x)//凸包周长
    {
    	RI i;double res=0;for(i=1;i^x.n;++i) res+=(x.p[i]-x.p[i+1]).len();
    	return res+(x.p[x.n]-x.p[1]).len();
    }
    int main()
    {
    	RI i,Tt;scanf("%d",&Tt);W(Tt--)
    	{
    		for(F.read(n,m),i=1;i<=n;++i) F.read(p[i].x,p[i].y);//读入数据
    		printf("%.0lf
    ",PolygonC(GetConvexHull(n,p))+2*pi*m),Tt&&(putchar('
    '),0);//输出答案
    	}return 0;
    }
    
  • 相关阅读:
    TensorFlow(十五):使用inception-v3实现各种图像识别
    TensorFlow(十四):谷歌图像识别网络inception-v3下载与查看结构
    TensorFlow(十三):模型的保存与载入
    TensorFlow(十二):使用RNN实现手写数字识别
    TensorFlow(十一):递归神经网络(RNN与LSTM)
    TensorFlow(十):卷积神经网络实现手写数字识别以及可视化
    ffmpeg-20160628-git-bin.7z
    ffmpeg-20160617-git-bin.7z ffmpeg-20160626-git-bin.7z
    欧洲杯 2016 高清直播
    YY 神曲 李明霖 14部合集
  • 原文地址:https://www.cnblogs.com/chenxiaoran666/p/UVA1303.html
Copyright © 2011-2022 走看看