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,坐标是 ...
随机推荐
- ASP.NET MVC中的Session以及处理方式
最近在ASP.NET MVC项目中碰到这样的情况:在一个controller中设置了Session,但在另一个controller的构造函数中无法获取该Session,会报"System.N ...
- AutoCAD二次开发——AutoCAD.NET API开发环境搭建
AutoCAD二次开发工具:1986年AutoLisp,1989年ADS,1990年DCL,1993年ADS-RX,1995年ObjectARX,1996年Active X Automation(CO ...
- Jersey 框架取到所有参数的方法
/** * 测试post取参数 * * @return */ @POST @Consumes("application/x-www-form-urlencoded") p ...
- [Git ] Git 使用规范流程
reference : http://www.ruanyifeng.com/blog/2015/08/git-use-process.html 团队开发中,遵循一个合理.清晰的Git使用流程,是非常重 ...
- 加载依赖的jar包在命令行编译和运行java文件
在命令里编译和执行java文件,当应用程序需要需要依赖的jar包里面的class文件才能编译运行的时候,应该这样做: 1. 首先是编译过程,在命令行里面执行: (1) javac -classpath ...
- mongodb实现远程连接
mongodb远程连接配置分为以下4步: 1. 添加管理员账户 > use admin switched to db admin > db.addUser('tank','test'); ...
- LeetCode 84. Largest Rectangle in Histogram 单调栈应用
LeetCode 84. Largest Rectangle in Histogram 单调栈应用 leetcode+ 循环数组,求右边第一个大的数字 求一个数组中右边第一个比他大的数(单调栈 Lee ...
- Spring MVC 4.2 CORS 跨域访问
跨站 HTTP 请求(Cross-site HTTP request)是指发起请求的资源所在域不同于该请求所指向资源所在的域的 HTTP 请求.比如说,域名A(http://domaina.examp ...
- Spark Streaming updateStateByKey案例实战和内幕源码解密
本节课程主要分二个部分: 一.Spark Streaming updateStateByKey案例实战二.Spark Streaming updateStateByKey源码解密 第一部分: upda ...
- Style 的查找 FindResource
1)根据名称查找 PrintPreview fe = new PrintPreview(new Summary()); string strResourceHeader = "headerS ...