BZOJ 1113 Wall ——计算几何
凸包第一题。
自己认为自己写的是Andrew
其实就是xjb写出来居然过掉了测试。
刚开始把pi定义成了int,调了半天
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define eps 1e-10
#define ll long long
#define mp make_pair const double pi=acos(-1.0); struct Vector{
double x,y;
void print()
{
printf("Vector - > (%.3f,%.3f)\n",x,y);
}
};
struct Point{
double x,y;
void print()
{
printf("Point - > (%.3f,%.3f)\n",x,y);
}
}; double operator * (Vector a,Vector b)
{return a.x*b.y-a.y*b.x;} Vector operator + (Vector a,Vector b)
{Vector ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;} Vector operator - (Vector a,Vector b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} Point operator + (Point a,Vector b)
{Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;} Vector operator * (Vector a,double b)
{Vector ret;ret.x=a.x*b;ret.y=a.y*b;return ret;} Vector operator - (Point a,Point b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} double dot (Vector a,Vector b)
{return a.x*b.x+a.y*b.y;} double len(Vector a)
{return sqrt(dot(a,a));} int n,l,top,sta[1005]; Point a[1005]; bool cmp(Point a,Point b)
{return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;} int main()
{
scanf("%d%d",&n,&l);
F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
sta[++top]=1;
F(i,2,n)
{
while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
sta[++top]=i;
}
D(i,n-1,1)
{
while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
sta[++top]=i;
}
double ans=0;
F(i,2,top)
{
ans+=len(a[sta[i]]-a[sta[i-1]]);
// (a[sta[i]]-a[sta[i-1]]).print();
}
ans+=2.0*l*pi;
// printf("%.6f\n",pi);
// printf("%.6f\n",2.0*l*pi);
printf("%d\n",(int)(ans+0.5));
}
BZOJ 1113 Wall ——计算几何的更多相关文章
- POJ 1113 Wall(计算几何の凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- POJ 1113 Wall(思维 计算几何 数学)
题意 题目链接 给出平面上n个点的坐标.你需要建一个围墙,把所有的点围在里面,且围墙距所有点的距离不小于l.求围墙的最小长度. \(n \leqslant 10^5\) Sol 首先考虑如果没有l的限 ...
- 【POJ】1113 Wall(凸包)
http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- ●POJ 1113 Wall
题链: http://poj.org/problem?id=1113 题解: 计算几何,凸包 题意:修一圈围墙把给出的点包围起来,且被包围的点距离围墙的距离不能小于L,求围墙最短为多少. 答案其实就是 ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- BZOJ 1113: [Poi2008]海报PLA
1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1025 Solved: 679[Submit][Statu ...
随机推荐
- Sublime Text 3 使用小记
快捷键: [ // 代码对齐插件 { "keys": ["shift+alt+a"], "command": "alignment ...
- Mybatis Learning Notes 1
Mybatis Learning Notes 主要的参考是博客园竹山一叶的Blog,这里记录的是自己补充的内容 实体类属性名和数据库不一致的处理 如果是实体类的结果和真正的数据库的column的名称不 ...
- libxml2.dylb 导致<libxml/tree.h> 老是找不到头文件
添加了libxml2.dylb的framework ,结果还是引用不了<libxml/tree.h>, 老是提示找不到头文件. 这个问题其实比较容易解决,但是XCode的版本问题确实让开 ...
- mac 上使用移动硬盘
1. 打开终端,查看赢盘的Volume Name diskutil list 2. 更新fstab文件,此步骤需要输入密码 sudo nano /etc/fstab 3. 在fstab文件中写入一下内 ...
- linux虚拟机安装值得注意的几点
1.建立新的虚拟机时选择自定义安装并选择稍后安装操作系统 2.关键安装命令 tar -xzvf VMwareTools-10.0.6-3595377.tar.gz sudo ./wmware-ins ...
- shell脚本,提取ip地址和子网掩码,和查外网ip地址信息。
#提取IP地址和子网掩码 [root@localhost ~]# ifconfig eth0|grep 'inet addr'|awk -F'[ :]+' '{print $4"/& ...
- 51nod 1135 原根 (数论)
题目链接 建议与上一篇欧拉函数介绍结合食用. 知识点:1.阶:a和模m互质,使a^d≡1(mod m)成立的最小正整数d称为a对模m的阶(指数) 例如: 2^2≡1(mod3),2对模3的阶为2; ...
- systemverilog(3)之Randomize
what to randomize? (1) primary input data <==one data (2)encapsulated input data <== muti grou ...
- PHP开发中涉及到emoji表情的几种处理方法!
emoji表情 处理 一般Mysql表设计时,都是用UTF8字符集的.把带有emoji的昵称字段往里面insert一下就没了,整个字段变成了空字符串.这是怎么回事呢? 原来是因为Mysql的utf8字 ...
- 格式化输出,基本运算符,流程控制主if
5.5自我总结 一.格式化输出 1.占位符 a = 1 b = 2 print('%S %s'%(a,b)) #1 2 print('%s %s'%(1,2)) #1 2 2.format格式化 a ...