Surround the Trees
来源:互联网 发布:朱莉德尔佩 知乎 编辑:程序博客网 时间:2024/06/05 00:15
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.
There are no more than 100 trees.
Zero at line for number of trees terminates the input for your program.
The minimal length of the rope. The precision should be 10^-2.
9 12 7 24 9 30 5 41 9 80 7 50 87 22 9 45 1 50 7 0
243.06
求凸包
#include<iostream>
#include <iomanip>
#include<algorithm>
#include<cmath>
using namespace std;
struct Point{
int x;
int y;
}p[1000000];
Point queue[10000];
Point start;
double distance1(Point a,Point b)
{
return sqrt(pow(b.x-a.x,2)+pow(b.y-a.y,2));
}
double direction(Point a,Point b,Point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool cmp(const Point a,const Point b)
{
int k=(a.x-start.x)*(b.y-start.y)-(b.x-start.x)*(a.y-start.y);
if(k>0)
{
return true;
}
if(k==0)
{
if(distance1(start,a)<distance1(start,b))
return true;
}
return false;
}
void ConvexB(int n)
{
queue[0]=p[0];
queue[1]=p[1];
queue[2]=p[2];
int count=3;
int top=2;
for(int i=3;i<n;i++)
{
while(count>=2)
{
Point nexttop=queue[top-1];
Point front=queue[top];
int dir=direction(nexttop,front,p[i]);
if(dir>0)
{
break;
}
top--;
count--;
}
top++;
count++;
queue[top]=p[i];
}
if(top>=2)
{
double re=0.0;
for(int j=0;j<top;j++)
{
re+=distance1(queue[j],queue[j+1]);
}
re+=distance1(queue[top],queue[0]);
printf("%.2lf\n",re);
}
}
int main()
{
//freopen("in.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
int i=1;
int px=-1;
int py=-1;
int p1;
for(i=0;i<n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
if(py==-1||p[i].y<py)
{
px=p[i].x;
py=p[i].y;
p1=i;
}
if(p[i].y==py)
{
if(p[i].x<px)
{
px=p[i].x;
py=p[i].y;
p1=i;
}
}
}
if(n<=1)
{
cout<<0.00<<endl;
continue;
}
if(n==2)
{
printf("%.2lf\n",distance1(p[1],p[0]));
continue;
}
Point temp=p[0];
p[0]=p[p1];
p[p1]=temp;
start=p[0];
sort(p+1,p+n,cmp);
ConvexB(n);
}
return 0;
}
- 1392 Surround the Trees
- Surround the Trees
- Surround the Trees
- Surround the Trees
- Surround the Trees
- hdu1392-Surround the Trees
- Surround the Trees
- Surround the Trees
- Surround the Trees HDU
- HDU 1392 Surround the Trees
- HDU 1392 Surround the Trees
- zoj 1453 Surround the Trees
- hdu 1392 Surround the Trees
- HDU 1392 Surround the Trees
- HDU 1392 Surround the Trees
- hdu 1392 Surround the Trees
- hdu 1392 Surround the Trees
- HDU 1392 Surround the Trees
- 制作initramfs镜像
- webview放大和缩小
- Cocos2d-x学习笔记(十)实例——记住帐号(密码)功能
- Hdu 1069 Monkey and Banana -- DP
- 《TCP-IP详解 卷1:协议》学习笔记(一)
- Surround the Trees
- 网络运维与管理2013超值精华本
- 纯技术角度分析目前二代身份证存在的安全缺陷及解决方案
- andriod学习——Content的openFileOutput 和 openFileInput操作文件
- hdu 4274 Spy's Work
- VS 2010 快捷键
- 总结的php10个常用的处理字符串的函数事例
- 华为助力Vert巴西分公司部署数据中心
- 反省一下>.<