poj 1113 Mall
水题:注意题目上面有一个至少离城堡的距离为L,其实思考一下就知道是指离凸包(凸多边形)的距离为L,这时很容易知道外围的圆的圆心角叠加之后就是一个整圆;和poj2187一样使用graham形成凸包;还有就是开始我四舍五入用floor(),却使用%d输出,导致一直输出是0;因为floor()的返回值也是浮点型。。。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<string.h>
- #include<algorithm>
- #include<map>
- #include<queue>
- #include<vector>
- #include<cmath>
- #include<stdlib.h>
- #include<time.h>
- using namespace std;
- const double PI = acos(-1.0);
- const int MAXN = 5e4+;
- struct point{
- int x,y;
- point(){}
- point(int _x,int _y){
- x = _x; y = _y;
- }
- int operator *(const point &b)const{
- return (x*b.y - y*b.x);
- }
- point operator -(const point &b)const{
- return point(x - b.x,y - b.y);
- }
- void input(){
- scanf("%d%d",&x,&y);
- }
- }p[MAXN];
- int dist2(point a,point b)
- {
- return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
- }
- bool cmp(point a,point b) // 正表示逆时针,返回true表示不要交换;
- {
- int cp = (a-p[])*(b-p[]);
- if(cp < ) return false;
- if(cp == && (dist2(a,p[]) >= dist2(b,p[])) ) return false;
- return true;
- }
- int stk[MAXN],top;
- void graham(int n) // 形成凸包;
- {
- int i;
- stk[] = ;stk[] = ;
- top = ;
- for(i = ;i < n;i++){ // 构造一个逆时针旋转的单调栈;
- while(top > && (p[stk[top]] - p[stk[top-]])*(p[i] - p[stk[top-]]) <= )
- top--;
- stk[++top] = i;
- }
- stk[++top] = ;//为了下面%top,很容易知道n-1号元素一定在凸包里面;
- /*for(i=0;i<n;i++)
- printf("**%d %d\n",p[i].x,p[i].y);
- printf("\n%d\n",top); // 0 ~ top - 1;
- for(i=0;i<top;i++)
- printf("**%d %d\n",p[stk[i]].x,p[stk[i]].y);*/
- }
- double solve()
- {
- double ans = ;
- for(int i = ;i < top;i++){
- ans += sqrt(.*dist2(p[stk[i]],p[stk[i+]]));
- }
- return ans;
- }
- int main()
- {
- int i,n,L;
- while(scanf("%d%d",&n,&L) == ){
- for(i = ;i < n;i++)
- p[i].input();
- int st = ;
- for(i = ;i < n;i++) // 选出起始点;
- if(p[st].y > p[i].y||(p[st].y == p[i].y && p[st].x > p[i].x))
- st = i;
- swap(p[],p[st]);
- sort(p+,p+n,cmp);// 以p[0]为参考点逆时针极角由进到远排序;
- graham(n);
- printf("%d\n",int(solve() + PI**L + 0.5));
- }
- return ;
- }
poj 1113 Mall的更多相关文章
- 计算几何--求凸包模板--Graham算法--poj 1113
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28157 Accepted: 9401 Description ...
- poj 1113 凸包周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33888 Accepted: 11544 Descriptio ...
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- 【POJ 1113】Wall
http://poj.org/problem?id=1113 夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题 我WA两次错在四舍五入上了(=゚ω゚)ノ #include<cmath& ...
- poj 1113 Wall
题目链接:http://poj.org/problem?id=1113 题目大意:给出点集和一个长度L,要求用最短长度的围墙把所有点集围住,并且围墙每一处距离所有点的距离最少为L,求围墙的长度. 解法 ...
- ●POJ 1113 Wall
题链: http://poj.org/problem?id=1113 题解: 计算几何,凸包 题意:修一圈围墙把给出的点包围起来,且被包围的点距离围墙的距离不能小于L,求围墙最短为多少. 答案其实就是 ...
- POJ 1113 Wall(凸包)
[题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- 文件I/O(不带缓冲)之open函数
调用open函数可以打开或创建一个文件. #include <fcntl.h> int open( const char *pathname, int oflag, ... /* mode ...
- 实例源码--Android简单团购应用源码
下载源码 技术要点: 1.HTTP通信技术 2.XML数据解析 3.控件的简单应用 4.源码带有非常详细的中文 注释 ...... 详细介绍: 1. HTTP通信技术 通 过HTTP通信技术, ...
- java_spring_bean的作用域_实例是否为单实例
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring – ${} is not working in @Value--转载
原文:http://www.mkyong.com/spring/spring-is-not-working-in-value/ By mkyong | February 4, 2015 | Last ...
- Reviewing the Blog Module
Reviewing the Blog Module Throughout the tutorial, we have created a fully functional CRUD module us ...
- 2、netlink简介
Netlink 是一种特殊的 socket,它是 Linux 所特有的,类似于 BSD 中的AF_ROUTE 但又远比它的功能强大,目前在最新的 Linux 内核(2.6.14)中使用netlink ...
- Nodepad ++
Nodepad ++是一个很好用的记事本工具.轻巧.打开文本速度要比windows内置的记事本快,而且功能众多. 支持多种语言,关键字高亮显示 并且可以折叠 内置n种主题,随时换 文件内容一变随时提醒 ...
- 【转】ubuntu修改IP地址和网关的方法
一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...
- 关于iOS自定义返回按钮右滑返回手势失效的解决:
在viewDidLoad方法里面添加下面这一句代码即可 self.navigationController.interactivePopGestureRecognizer.delegate=(id)s ...
- opencv拼接相关1
这里面都是一些比较杂的东西,没什么实际意义.主要是为了,后面能跑一个程序: Stitcher: 抠细节: http://docs.opencv.org/2.4.2/modules/stitching/ ...