此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包。

初次提交被坑得很惨,在GDB中可以完美运行A掉,到OJ上就频频RE(此处应有黑人问号)

后来发现了问题,原因是玩杂耍写了这样的代码

struct point {
int x, y;
point (){
scanf("%d%d", &x, &y);
}
...
}pt[MAXN];

于是乎,在swap

void swap(point &a, point &b){
point t = a;
a = b;
b = t;
}

的时候临时变量把数据读进去了,GG

//Ps. 我感觉这个代码高亮比上次的好看

//POJ1113
//凸包
//AC 2016.10.13 #include "cstdio"
#include "cstdlib"
#include "cmath"
#include "iostream"
#define MAXN 1010
const double pi = acos(-1.0); double sqr(double x){
return x * x;
} struct point {
int x, y;
point (){}
point (int X, int Y): x(X), y(Y) {}
double norm(){
return sqrt(sqr(x) + sqr(y));
}
friend bool operator < (const point &p1, const point &p2){
return (p1.x < p2.x)||(p1.x == p2.x)&&(p1.y < p2.y);
}
friend bool operator > (const point &p1, const point &p2){
return (p1.x > p2.x)||(p1.x == p2.x)&&(p1.y > p2.y);
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend int operator ^ (const point &p1, const point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
}pt[MAXN]; void swap(point &a, point &b){
point t = a;
a = b;
b = t;
} int main(){
int n, l;
freopen("fin.c", "r", stdin);
scanf("%d%d", &n, &l);
for (int i = 0; i < n; i++){
scanf("%d%d", &pt[i].x, &pt[i].y);
for (int j = i; j && (pt[j - 1] > pt[j]); j--)
swap(pt[j - 1], pt[j]);
}
int cur = 0;
double res = 0;
while (1){
int tmp = - 1;
for (int i = 0; i < n; i++)
if (i != cur){
if (tmp == - 1)
tmp = i;
else if (((pt[cur] >> pt[i]) ^ (pt[cur] >> pt[tmp])) > 0)
tmp = i;
}
res += (pt[cur] >> pt[tmp]).norm();
cur = tmp;
if ((tmp == - 1)||(!tmp)) break;
}
printf("%d\n", (int)(res + 2 * pi * l + 0.5));
return 0;
}

POJ 1113 - Wall 凸包的更多相关文章

  1. POJ 1113 Wall 凸包 裸

    LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...

  2. poj 1113 Wall 凸包的应用

    题目链接:poj 1113   单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...

  3. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  4. poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43274   Accepted: 14716 Descriptio ...

  5. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  6. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  7. POJ 1113 Wall(凸包)

    [题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...

  8. POJ 1113 Wall 求凸包

    http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...

  9. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

随机推荐

  1. github 如何合并不同分支

    From: http://stackoverflow.com/questions/1123344/merging-between-forks-in-github 1. 添加remote origina ...

  2. 20151214下拉列表:DropDownList

    注意: .如果用事件的话就要把控件的AutoPostBack设置成true .防止网页刷新用一个判断 if (!IsPostBack)//判断是第一个开始还是取的返回值 { } 下拉列表:DropDo ...

  3. [转]MySQL服务器上添加一个允许远程访问的用户

    MySQL默认是没有开启远程控制的,必须添加远程访问的用户,如果是安装版的话,从MySQL提供的控制台进入. 用root用户登陆,然后: grant all privileges on 数据库名.表名 ...

  4. ImageMagick Windows x64下的安装

    在windows下安装ImageMagick时,安装的版本一定要跟php的插件是同一个的,包含vc++编译的版本. 我使用的是ImageMagick-6.9.3-7-Q16-x64-dll.exe 和 ...

  5. [redis] redis.clients.jedis.exceptions.JedisDataException: MOVED 13102 127.0.0.1

    这个异常上网查了很久才知道原因: MOVED indicates that you're using Redis Cluster. ShardedJedis is not for Redis Clus ...

  6. elasticsearch【更新】操作

    基于上一篇博文基础上,进行es的操作,document的新增比较简单,就不说了,这里主要说说更新操作. 更新操作,有两大类,一个是Replace,一个是Update,就是说一个是替换,一个是更新. 替 ...

  7. C#特性学习笔记二

    实例探讨: 自定义了一个特性类: [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method)] class WahAttribute ...

  8. SVD分解的理解[转载]

    http://www.bfcat.com/index.php/2012/03/svd-tutorial/ SVD分解(奇异值分解),本应是本科生就掌握的方法,然而却经常被忽视.实际上,SVD分解不但很 ...

  9. Catalan数(数论)

    Catalan数 [参考网址]http://www.cnblogs.com/gongxijun/p/3232682.html 记得当时我们队写过一个,差点超时,现在找到了公式,感觉还是挺简单的. 还要 ...

  10. html5 xdm 页面之间的通信

    <!-- 这个是父页面xdm.html --><!DOCTYPE html> <html> <head> <meta charset=" ...