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 ...
随机推荐
- spring Transaction Management --官方
原文链接:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html 12. ...
- 网络请求OkHttp的使用
okHttp: 1.okHttp是squere公司出的,在Android4.0以后盛行 2.httpClient 在5.0中弃用,在6.0以Google的sdk中没有该api 3.httpUrlCo ...
- Servlet原理
Servlet主要用来处理客户端请求并将其结果发送到客户端,下面我们来详细看一下Servlet. 一.Servlet的生命周期 Servlet的生命周期是由Servlet的容器来控制的(Tomcat ...
- 《编写高质量代码》CSS部分总结
如何组织CSS 三层结构:base+common+page 分层目的:减少代码量:便于多人开发和维护 1.base层 最底层,一般设置文件为只读,与具体的UI无关,提供: reset功能.因为浏览器对 ...
- 【转】MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
[转]MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作 上一篇博文MyBatis学习总结(一)——MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据, ...
- C#学习笔记1:正则表达式和数据库连接
1.using System.Text.RegularExpressions; 只有导入该命名空间,才能引入Regex对象,IsMatch是Regex中的一个方法,作用是来判断(输入)内容是否满足正则 ...
- C#中调用存储过程
[csharp] view plain copy print? string strsql = "Data Source=192.168.24.53;Initial Catalog=JF_C ...
- c#转义字符串中的所有正则特殊字符
/// <summary> /// 转义字符串中所有正则特殊字符 /// </summary> /// <param name="input"> ...
- StrHelper
public class StrHelper { private static string passWord; //加密字符串 /// <summary> /// 判断输入是否数字 // ...
- 详解Windows 7系统中IE8/IE9/IE10三个版本的关系(转)
今年(2013)年初,微软开放了姗姗来迟的 IE10 for Windows 7 版本下载.至此,Windows 7 平台上可以运行三个 IE 浏览器版本.虽然 Windows 与 IE 经历了诸多版 ...