POJ 1113&&HDU 1348
题意:凸包周长+一个完整的圆周长。因为走一圈,经过拐点时,所形成的扇形的内角和是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的更多相关文章
- POJ 1113 || HDU 1348: wall(凸包问题)
传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- 计算几何--求凸包模板--Graham算法--poj 1113
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28157 Accepted: 9401 Description ...
- POJ 2104&HDU 2665 Kth number(主席树入门+离散化)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 50247 Accepted: 17101 Ca ...
- poj 1113 凸包周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33888 Accepted: 11544 Descriptio ...
- 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 ...
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- Eight POJ - 1077 HDU - 1043 八数码
Eight POJ - 1077 HDU - 1043 八数码问题.用hash(康托展开)判重 bfs(TLE) #include<cstdio> #include<iostream ...
随机推荐
- centos7 下手动安装MySQL-5.6.32-1.linux_glibc2.5.x86_64.rpm-bundle
由于centos7默认不再是mysql数据库,所以度算手动安装一个. 全程参考http://www.2cto.com/database/201501/371451.html 这里摘抄以下这个链接的内容 ...
- centos最小安装 setuptools安装
centos运行不了setup?那安装setuptool吧,可以节省很多系统管理的时间. #安装setuptoolyum install setuptool#可以发现执行setup后不全,再安装一个用 ...
- Django 后台搭建
# Django settings for gameadmin project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Nam ...
- Chp3: Stacks and Queue
1. 说明如何用两个队列来实现一个栈,并分析有关栈操作的运行时间. 解法:1.有两个队列q1和q2,先往q1内插入a,b,c,这做的都是栈的push操作.2.现在要做pop操作,即要得到c,这时可以将 ...
- hdu 3927 Math Geek
纯数论题,不解释!!!! 代码如下: #include<stdio.h> int main(){ ,m; scanf("%d",&t); while(t--){ ...
- hibernate annotation注解 主键ID自增长
@Id @SequenceGenerator(name="increment") @GeneratedValue(strategy=GenerationType.AUTO, gen ...
- Map.entrySet() 简介
转载:http://blog.csdn.net/mageshuai/article/details/3523116 今天看Think in java 的GUI这一章的时候,里面的TextArea这个例 ...
- 李洪强iOS开发之 - WebViewJavascriptBridge
李洪强iOS开发之 - WebViewJavascriptBridge 01 - JS端: 02 - iOS端 01 遵守代理协议 02 申明属性 03 开启日志 04 给哪个webview建立J ...
- 【HDOJ】4355 Party All the Time
好久没做过三分的题目了. /* 4355 */ #include <iostream> #include <sstream> #include <string> # ...
- poj3274
很不错的hash 优化有两个方面:1.根据题目换一个更优化的算法 2.在算法运行过程中优化 这题除了暴力好像没别的办法了吧? 但是暴力也是有策略的! 到第i只牛特征为j的总数为sum[i,j]; 找到 ...