Wall--POJ1113(极角排序+求凸包)
2016-05-17 09:00
453 查看
http://poj.org/problem?id=1113
题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l
分析 :现在就是求凸包的周长然后再加上一个圆的周长
题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l
分析 :现在就是求凸包的周长然后再加上一个圆的周长
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> #include<iostream> #include<queue> using namespace std; #define N 1005 #define pi acos(-1.0) #define ESP 1e-8 int s ; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} Point operator - (const Point &temp)const { return Point(x-temp.x,y-temp.y); } Point operator + (const Point &temp)const { return Point(x+temp.x,y+temp.y); } bool operator == (const Point &temp)const { return (x==temp.x && y==temp.y); } double operator * (const Point &temp)const { return (x*temp.x+y*temp.y); } int operator ^ (const Point &temp)const{ double t=x*temp.y-y*temp.x; if(t>ESP) return 1; if(fabs(t)<ESP) return 0; return -1; } }a ; double dist(Point a,Point b) { return sqrt((a-b)*(a-b)); } int cmp(Point a1,Point a2) { int t=((a1-a[0])^(a2-a[0])); if(t==0) return dist(a1,a[0])<dist(a2,a[0]); else return t>0; } int top; void Graham(int n)///求凸包 { s[0]=0; s[1]=1; top=1; for(int i=2;i<n;i++) { while(top>0 && ((a[i]-a[s[top]])^(a[s[top-1]]-a[s[top]]))<=0) top--; s[++top]=i; } } int main() { int n,l; while(scanf("%d %d",&n,&l)!=EOF) { memset(s,0,sizeof(s)); int k=0; for(int i=0;i<n;i++) { scanf("%lf %lf",&a[i].x,&a[i].y); if(a[i].y<a[k].y || (a[i].y==a[k].y && a[i].x<a[k].x)) k=i; } swap(a[0],a[k]); sort(a+1,a+n,cmp); Graham(n); double C=0; for(int i=1;i<=top;i++) { C+=dist(a[s[i]],a[s[i-1]]); } C+=dist(a[s[0]],a[s[top]]); C+=2*pi*l; printf("%.0lf\n",C); } return 0; }
相关文章推荐
- 根据psy输出sql
- 块状链表
- (礼拜二log)java 构建层级关系的递归算法
- host切换神器 firfox hostadmin
- 解决Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- LeetCode 143. Reorder List
- OpenGL矩阵变换
- 摇一摇
- 计步器
- 图片转为NSDasta
- CoreLocation Authorization in iOS8+
- tomcat 下 发布项目路径
- java 类和对象2
- SICP ex2-29
- 解析Java中PriorityQueue优先级队列结构的源码及用法
- 经纬度对应的距离
- iOS实现自定义的弹出视图(popView)
- 81. Search in Rotated Sorted Array
- Angularjs中的事件广播 ―全面解析$broadcast,$emit,$on
- 世界各国国家代码简称 - 备用