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,坐标是 ...
随机推荐
- Mybatis最入门---代码自动生成(generatorConfig.xml配置)
[一步是咫尺,一步即天涯] 经过前文的叙述,各位看官是不是已经被Mybatis的强大功能给折服了呢?本文我们将介绍一个能够极大提升我们开发效率的插件:即代码自动生成.这里的代码自动生成包括,与数据库一 ...
- blkblock工具1
http://www.ibm.com/developerworks/cn/linux/l-cn-perf1/ http://blog.chinaunix.net/uid-24774106-id-409 ...
- msgpack传文件
msgpack传文件 procedure TForm1.Button1Click(Sender: TObject);var ms, ms2: TMemoryStream; pack: TSimpleM ...
- Oracle数据库--解决单张表中数据量巨大(大数据、数据量上百万级别,后查询,更新数据等耗时剧增)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/QQ578473688/article/details/54561397 思路1:采用备份表 备份表中 ...
- 安卓5.1/7.1/8.1+wifi有叉问题解决
7.1/8.1 adb shell "settings put global captive_portal_http_url http://captive.v2ex.co/generate_ ...
- cas4.0 session中返回更多的用户信息
实现思路: 新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法.实际应用中我们只需要修改getPersion方法中的内容,根据实际情 ...
- 非常优秀的iphone学习文章总结!
This site contains a ton of fun tutorials – so many that they were becoming hard to find! So I put t ...
- 数学图形之罗马曲面(RomanSurface)
罗马曲面,像是一个被捏扁的正四面体. 本文将展示罗马曲面的生成算法和切图,使用自己定义语法的脚本代码生成数学图形.相关软件参见:数学图形可视化工具,该软件免费开源.QQ交流群: 367752815 维 ...
- 《Small Memory Software:Patterns For System With Limited Memory》读书笔记
原文地址:http://blog.csdn.net/jinzhuojun/article/details/13297447 虽然摩尔定律让我们的计算机硬件得以以指数速度升级,但反摩尔定律又不断消减这些 ...
- mahout源码KMeansDriver分析之四
昨天说到为什么Configuration没有设置conf.set("mapred.job.tracker","hadoop:9000")仍然可以访问hdfs文件 ...