题意:凸包周长+一个完整的圆周长。因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆。

模板题,之前写的Graham模板不对,WR了很多发。。。。POJ上的AC代码

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define clc(a,b) memset(a,b,sizeof(a))
#define eps 1e-8
#define PI acos(-1.0)
typedef long long LL;
const int mod=;
const int inf=0x3f3f3f3f;
const int MAXN=;
using namespace std; const int N = ; int top;
struct point
{
double x;
double y;
} p[N], Stack[N]; double dis(point A, point B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
} double crossProd(point A, point B, point C)
{
return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);
} int cmp(const void *a, const void *b)
{
point *c = (point *)a;
point *d = (point *)b;
double k = crossProd(p[], *c, *d);
if (k< || !k && dis(p[], *c)>dis(p[], *d))
return ;
return -;
} void Graham(int n)
{
double x = p[].x;
double y = p[].y;
int mi = ;
for (int i=; i<n; ++i)
{
if (p[i].x<x || (p[i].x==x && p[i].y<y))
{
x = p[i].x;
y = p[i].y;
mi = i;
}
}
point tmp = p[mi];
p[mi] = p[];
p[] = tmp;
qsort(p+, n-, sizeof(point), cmp);
p[n] = p[];
Stack[] = p[];
Stack[] = p[];
Stack[] = p[];
top = ;
for (int i=; i<=n; ++i)
{
while (crossProd(Stack[top-], Stack[top], p[i])<= && top>=) --top;
Stack[++top] = p[i];
}
} int main()
{
int n, l;
while (scanf("%d%d", &n, &l) != EOF)
{
for (int i=; i<n; ++i)
{
scanf ("%lf%lf", &p[i].x, &p[i].y);
}
Graham(n);
double ans=;
for(int i=;i<top;i++)
{
ans+=dis(Stack[i], Stack[i+]);
}
ans += PI * (l + l);
printf ("%d\n", (int)(ans+0.5));
}
return ;
}

POJ 1113&&HDU 1348的更多相关文章

  1. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

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

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

  3. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  4. POJ 2104&HDU 2665 Kth number(主席树入门+离散化)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Ca ...

  5. poj 1113 凸包周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33888   Accepted: 11544 Descriptio ...

  6. poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题

    poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...

  7. POJ 1113 Wall 凸包 裸

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

  8. poj 1113 Wall 凸包的应用

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

  9. Eight POJ - 1077 HDU - 1043 八数码

    Eight POJ - 1077 HDU - 1043 八数码问题.用hash(康托展开)判重 bfs(TLE) #include<cstdio> #include<iostream ...

随机推荐

  1. 4.3 spring-嵌入式beans标签的解析

    对于嵌入式的beans标签,想信大家很少使用过,或者接触过,起码,我本人就没用过. 它非常类似于Import标签所提供的功能; 使用如下: <?xml version="1.0&quo ...

  2. Extjs布局——layout: 'card'

    先看下此布局的特性: 下面演示一个使用layout: 'card'布局的示例(从API copy过来的)——导航面板(注:导航面板切换下一个或上一个面板实际是导航面板的布局--layout调用指定的方 ...

  3. encodeURIComponent()编码和decodeURIComponent()解码

    html1: <!DOCTYPE HTML> <meta charset=utf-8> <meta http-equiv="X-UA-Compatible&qu ...

  4. 三年PS经验

  5. Android中SQLite应用详解(转)

    上次我向大家介绍了SQLite的基本信息和使用过程,相信朋友们对SQLite已经有所了解了,那今天呢,我就和大家分享一下在Android中如何使用SQLite. 现在的主流移动设备像Android.i ...

  6. spoj 346

    当一个数大于等于12  那分别处以2, 3, 4之后的和一定大于本身    但是直接递归会超时    然后发现有人用map存了   膜拜..... #include <cstdio> #i ...

  7. Spark的TorrentBroadcast:概念和原理

    依据Spark 1.4.1源码 SparkContext的broadcast方法 注释 可以用SparkContext将一个变量广播到所有的executor上,使得所有executor都能获取这个变量 ...

  8. 【无聊放个模板系列】BZOJ 1597 斜率优化

    STL 双向队列DEQUE版本 #include<cstdio> #include<cstdlib> #include<cstring> #include<i ...

  9. SSH应该使用密钥还是密码?

    关于SSH,几乎每个人都同意密钥要优于密码,更安全,并且更先进,但我并不同意这个观点. 虽然密钥的确可以更好,但它有着还没被意识到的严重风险,并且我认为比得到妥善管理的密码更不安全. 通常密钥更好的理 ...

  10. PHP session过期时间

    如何设置一个严格30分钟过期的Session 今天在我的微博(Laruence)上发出一个问题: 我在面试的时候, 经常会问一个问题: “如何设置一个30分钟过期的Session?”, 大家不要觉得看 ...