poj 1113
来源:互联网 发布:网络理财投资 编辑:程序博客网 时间:2024/06/06 08:25
Description
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
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
Sample Input
9 100200 400300 400300 300400 300400 400500 400500 200350 200200 200
Sample Output
1628
Hint
Source
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
#define PI acos(-1.0)
int N,L,k;
struct point{
int x,y;
point (){};
point (int x,int y):x(x),y(y) {}
point mi (point b)
{
point cnt;
cnt.x=x-b.x;
cnt.y=y-b.y;
return cnt;
}
int det(point b)
{
return x*b.y-y*b.x;
}
double dis(point b)
{
return sqrt(double((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y)));
}
};
point ps[2000];
point qs[4000];
bool cmp(const point a,const point b)
{
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
void convex()
{
sort(ps , ps + N, cmp);
k=1;
qs[0]=ps[0];
qs[1]=ps[1];
for (int i=2;i<N;i++)
{
while(k>1&&((qs[k-1].mi(qs[k-2])).det(ps[i].mi(qs[k-1]))<=0)) k--;
qs[k++]=ps[i];
}
for (int i=N-2,t=k;i>=0;i--)
{
while(k>t&&((qs[k-1].mi(qs[k-2])).det(ps[i].mi(qs[k-1]))<=0)) k--;
qs[k++]=ps[i];
}
return ;
}
void slove()
{
double ans=0;
for (int i=0;i<k-1;i++)
{
ans+=(qs[i]).dis(qs[i+1]);
}
ans+=2*acos(-1.0)*L;
printf("%.0f\n",ans);
return;
}
int main()
{
while(scanf("%d%d",&N,&L)!=EOF)
{
for (int i=0;i<N;i++)
{
int a,b;
scanf("%d%d",&a,&b);
point cnt;
cnt.x=a;cnt.y=b;
ps[i]=cnt;
}
convex();
slove();
}
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
- ORACLE数据库的表管理(自学笔记)
- odbcConnectExcel is only usable with 32-bit Windows
- ios中的动画
- 全备份情况下,删除控制文件及恢复
- ubuntu系统文件夹目录说明
- poj 1113
- R语言基础编程技巧汇编 - 25
- JAVA通过Swing和socket编程实现简易点对点聊天
- Array类中的静态方法
- java自动装箱、拆箱
- 【Python】set与frozenset的区别
- if相关训练
- jquery 委托 on() | off()删除委托 | one()只执行一次的委托
- 闲谈JSP