[ACM_几何] Wall
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/E
题目大意:依次给n个点围成的一个城堡,在周围建围墙,要求围墙离城墙的距离大于一定的值,求围墙最短长度(结果四舍五入
解题思路:求围住所有点的凸包周长+一个圆的周长
#include<iostream>
#include<cmath>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<iomanip> using namespace std;
#define eps 0.0000000001
#define PI acos(-1.0) //*******************************************************************************
//点和向量
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector;
Vector operator-(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
bool operator<(const Vector& a,const Vector& b){return a.x<b.x||(a.x==b.x && a.y<b.y);}
int dcmp(double x){
if(fabs(x)<eps)return ;
else return x< ? -:;
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//向量点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量模长
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
//********************************************************************************
//计算凸包输入点数组p,个数n,输出点数组ch,返回凸包定点数
//输入不能有重复,完成后输入点顺序被破坏
//如果不希望凸包的边上有输入点,把两个<=改成<
//精度要求高时,建议用dcmp比较
//基于水平的Andrew算法-->1、点排序2、删除重复的然后把前两个放进凸包
//3、从第三个往后当新点在凸包前进左边时继续,否则一次删除最近加入的点,直到新点在左边
int ConVexHull(Point* p,int n,Point*ch){
sort(p,p+n);
int m=;
for(int i=;i<n;i++){//下凸包
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--){//上凸包
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
//*******************************************************************
int main(){
int n,L;
while(cin>>n>>L){ Point p[],ch[]; for(int i=;i<n;i++) //输入点
cin>>p[i].x>>p[i].y; int m=ConVexHull(p,n,ch); //求解凸包并计算凸包周长
double sum=Length(ch[]-ch[m-]);
for(int i=;i<m;i++)
sum+=Length(ch[i]-ch[i-]); printf("%.0lf\n", sum+*L*PI);//输出周长+圆周并四舍五入
}
return ;
}
[ACM_几何] Wall的更多相关文章
- [ACM_几何] Metal Cutting(POJ1514)半平面割与全排暴力切割方案
Description In order to build a ship to travel to Eindhoven, The Netherlands, various sheet metal pa ...
- [ACM_几何] UVA 11300 Spreading the Wealth [分金币 左右给 最终相等 方程组 中位数]
Problem A Communist regime is trying to redistribute wealth in a village. They have have decided to ...
- [ACM_几何] The Deadly Olympic Returns!!! (空间相对运动之最短距离)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/B 题目大意: 有两个同时再空间中匀速运动的导弹,告诉一个时间以 ...
- [ACM_几何] F. 3D Triangles (三维三角行相交)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28235#problem/A 题目大意:给出三维空间两个三角形三个顶点,判断二者是否有公共 ...
- [ACM_几何] Pipe
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/B 本题大意: 给定一个管道上边界的拐点,管道宽为1,求 ...
- [ACM_几何] Fishnet
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/C 本题大意:有一个1X1的矩形,每边按照从小到大的顺序给n ...
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- [ACM_几何] Transmitters (zoj 1041 ,可旋转半圆内的最多点)
Description In a wireless network with multiple transmitters sending on the same frequencies, it is ...
- 简单几何(凸包) POJ 1113 Wall
题目传送门 题意:求最短路线,使得线上任意一点离城堡至少L距离 分析:先求凸包,答案 = 凸包的长度 + 以L为半径的圆的周长 /*********************************** ...
随机推荐
- 如何去掉div滚动条
1.去掉横向滚动条 style="overflow-x:hidden" 2.去掉纵向滚动条 style="overflow-y:hidden" 3.同时去掉横向 ...
- LeetCode OJ-- Single Number II **@
有一列数,其中有1个数出现了1次,其它数都出现了3次,求这个数. class Solution { public: int singleNumber(int A[], int n) { ) ; ; ; ...
- 除法取模练习(51nod 1119 & 1013 )
题目:1119 机器人走方格 V2 思路:求C(m+n-2,n-1) % 10^9 +7 (2<=m,n<= 1000000) 在求组合数时,一般都通过双重for循环c[i][ ...
- mysql 相关问题解决
Windows下解决mysql中文乱码问题 在my.ini中, 在[mysqld]下添加 character_set_server = utf8 在[client]下添加 default-charac ...
- centos7.2进入单用户模式
1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh 4 - 现在按下 Co ...
- Global文件编译发布,代码不执行的问题与解决
问题:在Application_BeginRequest添加防止跨站点注入的过滤代码,VS2005编译成DLL发布后发现代码不会被执行: 环境:windows server 2008 r2 x64位 ...
- 大数据组件原理总结-Hadoop、Hbase、Kafka、Zookeeper、Spark
Hadoop原理 分为HDFS与Yarn两个部分.HDFS有Namenode和Datanode两个部分.每个节点占用一个电脑.Datanode定时向Namenode发送心跳包,心跳包中包含Datano ...
- linux中sed的用法【转】
sed命令行格式为: sed [-nefri] ‘command’ 输入文本/文件 常用选项: -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的 ...
- Html总结及日志目录
Html就是超文本标记语言的简写,是最基础的网页语言,代码都是由标签所组成,不用区分大小写. 1. Html代码由<html>开始</html>结束.里面由头部分<hea ...
- HTTP笔记整理(2)
四. http协议之请求 1.http请求由三部分组成,分别是:请求行(request line).请求报头(request header).请求正文(body) (1). 请求行:用来说明请求类 ...