题目:有非常多点。修一座最短的围墙把素有点围起来,使得全部点到墙的距离不小于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

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. typedef struct pnode
  10. {
  11. int x,y;
  12. double d;
  13. }point;
  14. point P[1005];
  15.  
  16. //叉乘
  17. int crossProduct(point a, point b, point c)
  18. {
  19. return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
  20. }
  21.  
  22. //两点间距离
  23. double dist(point a, point b)
  24. {
  25. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+0.0);
  26. }
  27.  
  28. //坐标比較
  29. int cmp1(point a, point b)
  30. {
  31. if (a.x == b.x) return a.y < b.y;
  32. return a.x < b.x;
  33. }
  34.  
  35. //斜率比較
  36. int cmp2(point a, point b)
  37. {
  38. int cp = crossProduct(P[0], a, b);
  39. if (!cp) return a.d < b.d;
  40. return cp > 0;
  41. }
  42.  
  43. //凸包
  44. double Graham(int n)
  45. {
  46. sort(P+0, P+n, cmp1);
  47. for (int i = 1 ; i < n ; ++ i)
  48. P[i].d = dist(P[0], P[i]);
  49. sort(P+1, P+n, cmp2);
  50.  
  51. int top = 1;
  52. for (int i = 2 ; i < n ; ++ i) {
  53. while (top > 0 && crossProduct( P[top-1], P[top], P[i] ) < 0) -- top;
  54. P[++ top] = P[i];
  55. }
  56. P[++ top] = P[0];
  57.  
  58. double L = 0.0;
  59. for ( int i = 0 ; i < top ; ++ i )
  60. L += dist(P[i], P[i+1]);
  61. return L;
  62. }
  63.  
  64. int main()
  65. {
  66. int t,n,l;
  67. while (~scanf("%d",&t))
  68. while (t --) {
  69. scanf("%d%d",&n,&l);
  70. for (int i = 0 ; i < n ; ++ i)
  71. scanf("%d%d",&P[i].x,&P[i].y);
  72.  
  73. printf("%.0lf\n",Graham(n)+acos(-1.0)*2*l);
  74. if (t) printf("\n");
  75. }
  76. return 0;
  77. }

UVa 1303 - Wall的更多相关文章

  1. 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall

    UVa 10618 Fixing the Great Wall 题目:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...

  2. UVa 10384 - The Wall Pushers

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVa 11040 (水题) Add bricks in the wall

    题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...

  4. UVa 900 - Brick Wall Patterns

    题目大意:用1*2的砖头建n*2的墙,问有多少种不同的砖头排列方式?与斐波那契序列相似. #include <cstdio> #define MAXN 60 #define N 50 un ...

  5. UVA 11040 Add bricks in the wall

    https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...

  6. UVA 11040 Add bricks in the wall(线性组合)

    砖块上的数字最终都可以看作是最后一行的线性组合,独立变元最多9个. 这类题的一般做法,线性组合都可以列出方程然后高斯消元. 对于这道题,只要确定最后一行剩下的4个变量就好了,对于最后一行的j位置,它对 ...

  7. UVA - 1045 The Great Wall Game(二分图最佳完美匹配)

    题目大意:给出棋盘上的N个点的位置.如今问将这些点排成一行或者一列.或者对角线的最小移动步数(每一个点都仅仅能上下左右移动.一次移动一个) 解题思路:暴力+二分图最佳完美匹配 #include < ...

  8. UVa 11040 Add bricks in the wall (水题递推)

    题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - ...

  9. UVa 1336 Fixing the Great Wall (区间DP)

    题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...

随机推荐

  1. ASP.NET MVC中的Session以及处理方式

    最近在ASP.NET MVC项目中碰到这样的情况:在一个controller中设置了Session,但在另一个controller的构造函数中无法获取该Session,会报"System.N ...

  2. AutoCAD二次开发——AutoCAD.NET API开发环境搭建

    AutoCAD二次开发工具:1986年AutoLisp,1989年ADS,1990年DCL,1993年ADS-RX,1995年ObjectARX,1996年Active X Automation(CO ...

  3. Jersey 框架取到所有参数的方法

    /**  * 测试post取参数  *   * @return  */ @POST @Consumes("application/x-www-form-urlencoded") p ...

  4. [Git ] Git 使用规范流程

    reference : http://www.ruanyifeng.com/blog/2015/08/git-use-process.html 团队开发中,遵循一个合理.清晰的Git使用流程,是非常重 ...

  5. 加载依赖的jar包在命令行编译和运行java文件

    在命令里编译和执行java文件,当应用程序需要需要依赖的jar包里面的class文件才能编译运行的时候,应该这样做: 1. 首先是编译过程,在命令行里面执行: (1) javac -classpath ...

  6. mongodb实现远程连接

    mongodb远程连接配置分为以下4步: 1. 添加管理员账户 > use admin switched to db admin > db.addUser('tank','test'); ...

  7. LeetCode 84. Largest Rectangle in Histogram 单调栈应用

    LeetCode 84. Largest Rectangle in Histogram 单调栈应用 leetcode+ 循环数组,求右边第一个大的数字 求一个数组中右边第一个比他大的数(单调栈 Lee ...

  8. Spring MVC 4.2 CORS 跨域访问

    跨站 HTTP 请求(Cross-site HTTP request)是指发起请求的资源所在域不同于该请求所指向资源所在的域的 HTTP 请求.比如说,域名A(http://domaina.examp ...

  9. Spark Streaming updateStateByKey案例实战和内幕源码解密

    本节课程主要分二个部分: 一.Spark Streaming updateStateByKey案例实战二.Spark Streaming updateStateByKey源码解密 第一部分: upda ...

  10. Style 的查找 FindResource

    1)根据名称查找 PrintPreview fe = new PrintPreview(new Summary()); string strResourceHeader = "headerS ...