UVa 1303 - Wall
题目:有非常多点。修一座最短的围墙把素有点围起来,使得全部点到墙的距离不小于l。
分析:计算几何,凸包。
假设。没有距离l的限制。则答案就是凸包的周长了。有了距离限制事实上是添加了2*π*l。
证明:如上图。在凸包外做相应边的矩形;
多边形内角和 = 180*(n-2);
外角和 = 360*n - 内角和 = 180*n+360;
全部直角和为2*90*n;
所以,全部扇形的内角和为360;即围栏比凸多边形周长多2*π*l。
说明:坐标比較a3.x < b.x 写成 a.x < b.y 查了好久才发现。o(╯□╰)o
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath> using namespace std; typedef struct pnode
{
int x,y;
double d;
}point;
point P[1005]; //叉乘
int crossProduct(point a, point b, point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} //两点间距离
double dist(point a, point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+0.0);
} //坐标比較
int cmp1(point a, point b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
} //斜率比較
int cmp2(point a, point b)
{
int cp = crossProduct(P[0], a, b);
if (!cp) return a.d < b.d;
return cp > 0;
} //凸包
double Graham(int n)
{
sort(P+0, P+n, cmp1);
for (int i = 1 ; i < n ; ++ i)
P[i].d = dist(P[0], P[i]);
sort(P+1, P+n, cmp2); int top = 1;
for (int i = 2 ; i < n ; ++ i) {
while (top > 0 && crossProduct( P[top-1], P[top], P[i] ) < 0) -- top;
P[++ top] = P[i];
}
P[++ top] = P[0]; double L = 0.0;
for ( int i = 0 ; i < top ; ++ i )
L += dist(P[i], P[i+1]);
return L;
} int main()
{
int t,n,l;
while (~scanf("%d",&t))
while (t --) {
scanf("%d%d",&n,&l);
for (int i = 0 ; i < n ; ++ i)
scanf("%d%d",&P[i].x,&P[i].y); printf("%.0lf\n",Graham(n)+acos(-1.0)*2*l);
if (t) printf("\n");
}
return 0;
}
UVa 1303 - Wall的更多相关文章
- 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall
UVa 10618 Fixing the Great Wall 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...
- UVa 10384 - The Wall Pushers
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- UVa 900 - Brick Wall Patterns
题目大意:用1*2的砖头建n*2的墙,问有多少种不同的砖头排列方式?与斐波那契序列相似. #include <cstdio> #define MAXN 60 #define N 50 un ...
- UVA 11040 Add bricks in the wall
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...
- UVA 11040 Add bricks in the wall(线性组合)
砖块上的数字最终都可以看作是最后一行的线性组合,独立变元最多9个. 这类题的一般做法,线性组合都可以列出方程然后高斯消元. 对于这道题,只要确定最后一行剩下的4个变量就好了,对于最后一行的j位置,它对 ...
- UVA - 1045 The Great Wall Game(二分图最佳完美匹配)
题目大意:给出棋盘上的N个点的位置.如今问将这些点排成一行或者一列.或者对角线的最小移动步数(每一个点都仅仅能上下左右移动.一次移动一个) 解题思路:暴力+二分图最佳完美匹配 #include < ...
- UVa 11040 Add bricks in the wall (水题递推)
题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - ...
- UVa 1336 Fixing the Great Wall (区间DP)
题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...
随机推荐
- 电感式升压转换器-AIC1896 电感式升压转换器
电感式升压转换器-AIC1896 AIC1896是一个脉冲宽度调变(Pulse-Width-Modulation;PWM)控制之升压型转换器,它可以提供一个定电流以驱动白光LED. (图五A)为升压转 ...
- mount nfs 经常出错信息总结(转)
通常当NFS不能正常使用时候会给出提示,一般给出一下几种: 1)mount: 192.168.1.111:/opt failed, reason given by server: Permission ...
- java string常见操作题
1. 每个基本类型封装类都有将string转换为基本数据类型的方法 对于非常大的数字请使用Long,代码如下 int age = Integer.parseInt("10"); ...
- java线程的一些基础小知识
--------------------------------------------------------------------------------------------------线程 ...
- 使用 SVWebViewController 推出浏览器控制器
SVWebViewController 简单翻译 https://github.com/samvermette/SVWebViewController SVWebViewController is a ...
- mac securecrt无法记住密码的解决方法
打开secureCRT,菜单preferences--general,找到mac options.然后去掉Use KeyChain选项,这样每次连接服务器后就会自动保存密码了.不同的版本可能这个选项的 ...
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)
格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://www.thermo.com/informatics/xmlns/limswebservice 进行反序列化时出错: Process ...
- java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path: DexPathL
java.lang.ClassNotFoundException: Didn't find class "stu.love.neihan.MainActivity" on path ...
- OpenCV教程(41) 人脸特征检测
在OpenCV中,自带着Harr分类器人脸特征训练的文件,利用这些文件,我们可以很方面的进行人脸,眼睛,鼻子,表情等的检测. 人脸特征文件目录: ../opencv2.46/op ...
- 如何关掉UAC?
你可能会问, 这也值得一写? 唉, 怎么说呢, 谁让咱一开始不会呢. ^_^ 好记性不如烂笔头嘛. 1. 打开一个command prompt, 输入msconfig回车. 2. 点击tools选 ...