博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【计算几何初步-凸包-Graham扫描法-极角序】【HDU1348】 WALL
阅读量:6892 次
发布时间:2019-06-27

本文共 5323 字,大约阅读时间需要 17 分钟。

Wall

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3779    Accepted Submission(s): 1066
Problem Description
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
 
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
 
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
 
Sample Input
 
1 9 100 200 400 300 400 300 300 400 300 400 400 500 400 500 200 350 200 200 200
 
Sample Output
 
1628
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 
 |   |   | 
 

题目本身不多说了

ANS=凸包周长+2*R*L 很容易证明

Graham算法的话 代码注释也有点解释

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define oo 0x13131313#define pi 3.1415926#define exp 10e-6using namespace std;int N,L;struct point{ double x,y;};point A[1050];point stk[1050];int s=0;int k;int start;double ans;double dist(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double crossdet(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1;}double cross(point a,point b,point c){ return crossdet(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);}double dotdet(double x1,double y1,double x2,double y2){ return x1*x2+y1*y2;}double dot(point a,point b,point c){ return dotdet(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);}int sgn(double x){ if(fabs(x)
0;}/*int cmp(point a,point b) //当叉积为0时通过距离比较的cmp { double temp=cross(A[1],a,b); double temp1; if(sgn(temp)==0) { return dist(a,A[1])
0;}/*int cmp(const void *i,const void *j) //qsort的cmp { point *a=(point *)i,*b=(point *)j; double re=cross(A[1],*a,*b); if(re==0) return dist(*a,A[1])>dist(*b,A[1]); return re<0;}*/void input(){ memset(stk,0,sizeof(stk)); memset(A,0,sizeof(A)); s=0;ans=0; cin>>N>>L; for(int i=1;i<=N;i++) { scanf("%lf%lf",&A[i].x,&A[i].y); }}void findmin(int &k) //寻找最小的y,同时最小的话选x小的 { k=1; for(int i=2;i<=N;i++) { if(sgn(A[i].y-A[k].y)<0) k=i; else if(sgn(A[i].y-A[k].y)==0&&(A[i].x-A[k].x)<0) k=i; }}void solve() { findmin(start); swap(A[1],A[start]);//小细节注意 // qsort(A+2,N-1,sizeof(A[1]),cmp); sort(A+2,A+N+1,cmp); for(int i=1;i<=2;i++) { stk[++s]=A[i]; //一开始二个肯定在的点入栈 } for(int i=3;i<=N;i++) { while(sgn(cross(stk[s-1],stk[s],A[i]))<=0&&s>=2) //1.防止下面的2个点退栈 2.若stk[i-1]A[i]不在stk[i-1]A[s]的逆时针方向 退栈 寻找更好的凸包 s--; stk[++s]=A[i]; //入栈 最终栈里面至少有3个点 也显然可知若即使只有3个点 则3个点都在凸包上 } for(int i=2;i<=s;i++) { ans+=dist(stk[i],stk[i-1]); } ans+=dist(stk[1],stk[s]);}void init(){ freopen("a.in","r",stdin); freopen("a.out","w",stdout); }int main(){ int T; //init(); cin>>T; int ttt=0; while(T--) { if(ttt++) printf("\n"); input(); solve(); if(N==1) ans=0; else if(N==2) ans=dist(A[1],A[2]); ans=ans+2*pi*L; //由题目显然克制 凸包周长加那个圆的面积 printf("%.0lf\n",ans); }}

转载于:https://www.cnblogs.com/zy691357966/p/5480426.html

你可能感兴趣的文章
Linux基本概念(2)
查看>>
maven搭建多模块项目
查看>>
常见的9款Java报表工具
查看>>
【oracle】Oracle12c安装及一些使用问题
查看>>
我的友情链接
查看>>
ppc64le centos7 安装confd 并结合etcd实现haproxy的高可用
查看>>
呼叫中心 ACD 系统的介绍
查看>>
使用PowerShell定时批量结束Citrix Xen App Session
查看>>
js本地缓存,页面传值
查看>>
Grafana3.1.0安装步骤
查看>>
c++获取进程的运行路径
查看>>
oracle 日常操作
查看>>
我的友情链接
查看>>
高级I/O---多路复用---poll
查看>>
计算机集群多任务投递脚本
查看>>
Flume数据采集之常见集群配置案例
查看>>
自定义ANDROID中EDITTEXT中的HINT文本的大小
查看>>
Unity3D下用C#通过WinSCP命令行方式给Linux服务器SCP传文件
查看>>
Fedora遇难记之rpmfusion:获取 GPG 密钥失败
查看>>
Exception
查看>>