Poj 1113 Hoj 1605 Wall
来源:互联网 发布:java初级工程师考证 编辑:程序博客网 时间:2024/05/13 17:44
题目连接:http://poj.org/problem?id=1113
http://acm.hit.edu.cn/hoj/problem/view?id=1605
本题是凸包的典型应用。求凸包用建议水平序,因为极角序要处理共线的问题。
参考:http://www.cnblogs.com/Booble/archive/2011/03/10/1980089.html
有一个问题是水平序的常用模板中。左链是否有机会回溯到右链。本题不加判断也是可以的。不知其它题目如何。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;struct Point{ int x; int y; Point() {} Point(int _x,int _y):x(_x),y(_y) {} friend Point operator + (Point a,Point b) { return Point(a.x+b.x , a.y+b.y); } friend Point operator - (Point a,Point b) { return Point(a.x-b.x , a.y-b.y); }};Point p[1002];Point stack[10002];double det(Point a,Point b){ return a.x*b.y-a.y*b.x;}double det(Point a,Point b,Point o){ return det(a-o,b-o);}double det(Point a,Point b,Point c,Point d){ return det(b-a,d-c);}bool cmp(Point a,Point b){ return a.y<b.y || (a.y == b.y && a.x<b.x);}double dis(Point a,Point b){ return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) );}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int n,l; while(scanf(" %d %d",&n,&l)!=EOF) { for(int i=0; i<n; i++) { scanf(" %d %d",&p[i].x,&p[i].y); } sort(p,p+n,cmp); int top = -1; stack[++top] = p[0]; stack[++top] = p[1]; for(int i=2; i<n; i++) { while(top && det(stack[top],p[i],stack[top-1]) < 0) { top--; } stack[++top] = p[i]; } //int midtop = top; for(int i=n-2; i>=0; i--) { //左链有可能会回溯到右链么?top>midtop是否不加也可以? //while(top>midtop && det(stack[top],p[i],stack[top-1]) < 0) while(det(stack[top],p[i],stack[top-1]) < 0) { top--; } stack[++top] = p[i]; } double ans = 2 * l * acos(-1.0); for(int i=0; i<top; i++) { ans += dis(stack[i],stack[i+1]); } ans += 0.5; printf("%d\n",(int)ans); } return 0;}
- Poj 1113 Hoj 1605 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113(Wall-Quickhull)
- POJ 1113 Wall
- poj-1113-Wall
- poj 1113 Wall
- POJ 1113 Wall
- POJ 1113 Wall
- 如何在自己ubtunbu上安装rabbitmq
- 排序之四:归并排序
- IncompleteElementException:Could not find result map java.util.Map异常
- Windows下删除.svn文件的最简单方法
- oracle 日志模式切换
- Poj 1113 Hoj 1605 Wall
- Teach Yourself Programming in Ten Years——用十年教会自己编程
- 位运算
- mmm-启动mmm-agent服务错误信息-Starting MMM Agent daemon... Can't locate Log/Log4perl.pm in @INC
- Boost智能指针——weak_ptr
- 【APP设计】设计移动 App 需要注意的 10 点
- HTTPS传输原理
- 第四章——SQLServer2008-2012资源及性能监控(1)
- Sniffer Pro 4.7.5注册不成功问题(unable to communicate with server)