hdu 1348 凸包模板
http://acm.hdu.edu.cn/showproblem.php?pid=1348
造城墙问题,求出凸包加上一圈圆的周长即可
凸包模板题
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
const int modo = 1e9 + 7;
const int maxn = 1e4 + 5;
struct point{
int x,y;
}a[maxn];
int b[maxn];
bool cmp(point a,point b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
double dis(point a,point b)
{
return sqrt(double((a.x-b.x)*(a.x-b.x)) + double((a.y - b.y)*(a.y - b.y)));
}
int cj(point a,point b,point c)
{
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) *(b.x - c.x);
}
int m;
void graham(int n)
{
sort(a,a+n,cmp);
b[0] = 0,b[1] = 1,b[2] = 2;
int k = 1;
for(int i = 2;i < n;++i){
while(k && cj(a[i],a[b[k]],a[b[k-1]]) >= 0)
--k;
b[++k] = i;
}
m = k;
b[++k] = n - 2;
for(int i = n - 3;i >= 0;--i){
while(k != m && cj(a[i],a[b[k]],a[b[k-1]]) >= 0)
--k;
b[++k] = i;
}
m = k;
}
int main() {
int n,_;double f;
RD(_);
while(_--){
RD(n);
scanf("%lf",&f);
for(int i = 0;i < n;++i){
RD2(a[i].x,a[i].y);
}
graham(n);
double ans = 0;
for(int i = 0;i < m;++i)
ans += dis(a[b[i]],a[b[i+1]]);
ans += dis(a[b[m]],a[b[0]]);
ans += pi * 2 *f;
printf("%.0lf\n",ans);
if(_>0)
puts("");
}
return 0;
}
hdu 1348 凸包模板的更多相关文章
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- hdu 1348(凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 计算几何(凸包模板):HDU 1392 Surround the Trees
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...
- hdu 2202 最大三角形_凸包模板
题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- HDU 1392 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 凸包模板 POJ1873
// 凸包模板 POJ1873 // n=15所以可以按位枚举求凸包,再记录数据 #include <iostream> #include <cstdio> #include ...
- HDU 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
随机推荐
- Centos7 vnc
这是一个关于怎样在你的 CentOS 7 上安装配置 VNC 服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置 VNC ...
- Mysql修改密码办法
方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...
- Redis的简介
Redis 简介 Redis 是一个高性能的key-value数据库.支持复杂的数据结构,支持持久化,支持主从集群,支持高可用,支持较大的value存储... Redis是一个nosql,非关系型数据 ...
- Redis事务的简单理解
Redis事务的命令如下所示: 先以 MULTI 开始一个事务, 然后将多个命令入队到事务中, 最后由 EXEC 命令触发事务, 一并执行事务中的所有命令 示例如下: //开始一个事务 > MU ...
- mysql增加远程连接用户及查看数据库表结构
一.增加远程连接用户 1.用root权限登录数据库 2.加用户:grant all privileges on *.* to '111'@'192.168.1.%' identified by '2 ...
- 14-matlab排序
冒泡和选择: clc; clear; n = 10; %输入数据的个数 suct = 0; %素数的个数 unsuct = 0;%非素数的个数 % a = [33 34 2 34 24 56 3 17 ...
- VC++ 定时器使用总结
VC++ WM_TIMER 定时器使用方法 在编程时,会经常使用到定时器.使用定时器的方法比较简单,通常告诉Windows一个时间间隔,然后WINDOWS以此时间间隔周期性触发程 ...
- js 递归调用
js递归调用 function fact(num) { ) { ; } else { ); } } 以下代码可导致出错: var anotherFact = fact; fact = null; al ...
- Laravel 中使用原生的 PHPExcel
1.安装 composer require maatwebsite/excel 之后,程序中就可以使用 PHPExcel 了 2.控制器中 public function export(Request ...
- mvc 验证封装到某个特征类里[特性的使用]