此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求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. Apache配置代理服务器的方法(1)

    众所周知Apache是目前最优秀的HTTP服务器.实际上它不仅能当作服务器使用,也能够被用来架设代理服务器.本文就如何使用Apache架设HTTP代理服务器进行说明. 本文将基于Win32版的Apac ...

  2. MSP430设置串口波特率的方法

    给定一个BRCLK时钟源,波特率用来决定需要分频的因子N:               N = fBRCLK/Baudrate 分频因子N通常是非整数值,因此至少一个分频器和一个调制阶段用来尽可能的接 ...

  3. ES pom配置

    https://github.com/elastic/elasticsearch/issues/19415 <dependency> <groupId>org.elastics ...

  4. 【Unity3D自学记录】判断物体是否在镜头内

    判断物体是否在镜头内. 其实很简单的方法 代码如下: using UnityEngine; using System.Collections; public class DJH_IsRendering ...

  5. ubuntu12.04+kafka2.9.2+zookeeper3.4.5的伪分布式集群安装和demo(java api)测试

    博文作者:迦壹 博客地址:http://idoall.org/home.php?mod=space&uid=1&do=blog&id=547 转载声明:可以转载, 但必须以超链 ...

  6. MapReduce 2简介

    在Hadoop 1.0版本中,mapred.job.tracker决定了执行MapReduce程序的方式,若设置为local,则使用本地的作业运行器,若设置为主机:端口(eb179:9001),则该配 ...

  7. javascript中的事件委托

    这几天看到一个面试题,大概就是,让你给1000个li都添加一个click事件,应该怎么添加?大多数人第一开始的感觉可能就是,每个li上边都添加一个呗,那要是这样的话,估计面试的时候就会GG了,这里就是 ...

  8. Android 百度地图的使用

    可以参考百度官网Android开发指南. 里面有详细的步骤和Sample例子. http://lbsyun.baidu.com/index.php?title=androidsdk/guide/int ...

  9. Delphi ActiveX Form的使用实例

    Delphi ActiveX Form的使用实例 By knityster 1. ActiveX控件简介 ActiveX控件也就是一般所说的OCX控件,它是ActiveX技术的一部分. ActiveX ...

  10. C#中Monitor类、Lock关键字和Mutex类

    线程:线程是进程的独立执行单元,每一个进程都有一个主线程,除了主线程可以包含其他的线程.多线程的意义:多线程有助于改善程序的总体响应性,提高CPU的效率.多线程的应用程序域是相当不稳定的,因为多个线程 ...