SSL 1720_Surround the Trees_凸包
来源:互联网 发布:2016年云计算政策 编辑:程序博客网 时间:2024/06/07 01:09
题目描述
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?
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.
思路
凸包模版题
#include <stdio.h>#include <cmath>#define maxn 10000#define INF 0x7f7f7f7fusing namespace std;inline int read(){ int x=0,p=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-')p=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*p;}struct arr{ int x,y; void intput(){x=read();y=read();}}e[maxn];double dist(arr a,arr b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int cros(arr a,arr b,arr c){ return (a.y-c.y)*(b.x-c.x)-(a.x-c.x)*(b.y-c.y);}int main(){ int n; while (scanf("%d",&n)&&n!=0) { for (int i=1;i<=n;i++) e[i].intput(); e[0]=(arr){INF,INF}; int t=0; for (int i=1;i<=n;i++) if (e[i].x<e[t].x||e[i].x==e[t].x&&e[i].y<e[t].y) t=i; double ans=0; int k=t,p; do { int i=0; double dis=0; for (int j=1;j<=n;j++) if (j!=k) { if (i) p=cros(e[k],e[i],e[j]); if (p<0||i==0) dis=dist(e[k],e[j]),i=j; } ans+=dis; k=i; } while (t!=k); if (n==1) ans=0; printf("%.2lf\n",ans); }}
0 0
- SSL 1720_Surround the Trees_凸包
- UVA_10007 Count the Trees_高精度
- SSL 1720 Surround the Trees
- Surround the Trees ssl 1720 计算几何
- The Apache + SSL HOWTO
- hdu1392Surround the Trees 凸包
- hdu_1392_Surround the Trees(凸包)
- Surround The Trees_ssl1720_凸包
- ssl socket 抓包验证
- UVa 10256 The Great Divide 凸包, 凸包分离
- 包 javax.net.ssl 不存在 import javax.net.ssl.SSLKeyException;
- Surround the Trees&&凸包入门题
- HDU1392--Surround the Trees--凸包
- HDU 1392 Surround the Trees(凸包)
- hdu_1392 Surround the Trees(凸包)
- UVA 10256 The Great Divide 凸包
- HDUJ 1392 Surround the Trees 凸包
- HDOJ_1392 Surround The Trees (凸包模版)
- python往mysql中插入数据时,中文乱码的问题
- TextView的跑马灯效果
- 三表关联一对多时sum函数的使用 demo
- 在Docker中运行 Nodejs 遇到的问题记录1
- cookie
- SSL 1720_Surround the Trees_凸包
- Resources的使用方式
- 数据结构实验之栈二:一般算术表达式转换成后缀式
- RadioGroup与Radio、复选框CheckBox
- 简单编程之字符串右移
- 241. Different Ways to Add Parentheses
- 开启博客之旅
- Redis实战之Redis + Jedis
- 玲珑oj 萌萌哒的第五题