poj 1113 Wall
来源:互联网 发布:手机拼音打字软件 编辑:程序博客网 时间:2024/04/29 08:56
大致题意:给定多边形城堡的n个顶点,绕城堡外面建一个围墙,围住所有点,并且墙与所有点的距离至少为L,求这个墙最小的长度。
解题思路:者很明显是一个凸包问题,围墙的长度=整个凸包的长度+pi*2*L
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;struct Point{int x;int y;};int N, d; // 顶点数Point shape[1000]; // 记录多边形各个顶点Point bulgeShape[1001]; // (栈)记录凸包中各顶点int top; // 栈顶
// 返回两点间距离double Dis( const Point & p1, const Point & p2 ){return sqrt( (double)((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)) );}// p2为交点, 返回p1在p2的什么方向int Mul( const Point & p1, const Point & p2, const Point & p3 ){return ( p1.x - p2.x ) * ( p3.y - p2.y ) - ( p3.x - p2.x ) * ( p1.y - p2.y );}/** 返回真表示p1与shape[0]的极角比p2与shape[0]的极角大*/bool cmp ( const Point p1, const Point p2 ){ return Mul( p1, shape[0], p2 ) > 0;}//寻找多边形shape的凸包,将凸包记录在bulgeShape中void Graham_Scan(){/* 寻找多边形的最低点,若有多个,则找最左边的点 */int i;int pos = 0;for( i = 1; i < N; ++ i ){if( shape[i].y < shape[pos].y || shape[i].y == shape[pos].y && shape[i].x < shape[pos].x )pos = i;}Point temp = shape[0];shape[0] = shape[pos];shape[pos] = temp;/* 对多边形中所有顶点按与shape[0]的极角大小从小到大排序(不考虑极角相等的情况) */sort( shape + 1, shape + N, cmp );/* 找凸包 */top = 0; // 置栈顶为空bulgeShape[top++] = shape[0];bulgeShape[top++] = shape[1];for( i = 2; i < N; ++ i ){/* 下面这句判断3点共线 */if( Mul( shape[i], bulgeShape[top-1], bulgeShape[top-2] ) == 0 && // 三点共线( (shape[i].x - bulgeShape[top-2].x) * (shape[i].x - bulgeShape[top-1].x) < 0 || // 且新点在另两点之间 (shape[i].y - bulgeShape[top-2].y) * (shape[i].y - bulgeShape[top-1].y) < 0 ) ){continue;}while( top - 2 >= 0 && Mul( shape[i], bulgeShape[top-1], bulgeShape[top-2] ) <= 0 ){-- top;}bulgeShape[top++] = shape[i];}}int main(){freopen("test.txt","r",stdin);int i;cin >> N >> d;for( i = 0; i < N; ++ i )cin >> shape[i].x >> shape[i].y;Graham_Scan();bulgeShape[top] = bulgeShape[0];double tempSum = 0;for( i = 0; i < top; ++ i ){tempSum += Dis( bulgeShape[i], bulgeShape[i+1] );}tempSum += 2 * 3.141592654 * d;int sum = (int)( tempSum + 0.5 );cout << sum << endl;return 0;}
- 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
- poj - 1113 - Wall
- android activity的生命周期 以及横竖屏切换
- 求两个数的正差值
- WebGoat教程解析——HTTP Response Splitting
- vc++学习之15 多线程与聊天室程序的创建
- 输出四个整数中的最大值
- poj 1113 Wall
- 第七周上机任务(求两个数的正差值)
- Android单模块编译方法
- Linux命令之trap - 在脚本中处理信号
- Git 魔法
- exit与atexit
- WPF TreeGrid(树形展开的表格)
- 优秀有价值的博客收藏列表(持续更新)
- MySQL索引与存储方式对性能的影响