凸包模板题目。

  1. /* 3285 */
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. #define MAXN 55
  10.  
  11. typedef struct {
  12. int x, y;
  13. } Point_t;
  14.  
  15. Point_t points[MAXN];
  16. Point_t stack[MAXN];
  17. int top;
  18.  
  19. void output(int);
  20.  
  21. double dist(Point_t a, Point_t b) {
  22. return sqrt(1.0*(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  23. }
  24.  
  25. int dist2(Point_t a, Point_t b) {
  26. return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
  27. }
  28.  
  29. int cross(Point_t a, Point_t b, Point_t c) {
  30. return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
  31. }
  32.  
  33. bool comp(Point_t a, Point_t b) {
  34. int m = cross(points[], a, b);
  35. return m> || (m== && dist2(points[], a)<dist2(points[], b));
  36. }
  37.  
  38. void Graham(int n) {
  39. Point_t p;
  40. int i, j, k;
  41.  
  42. p = points[];
  43. k = ;
  44. for (i=; i<n; ++i) {
  45. if (points[i].x<p.x || (points[i].x==p.x && points[i].y<p.y)) {
  46. p = points[i];
  47. k = i;
  48. }
  49. }
  50. points[k] = points[];
  51. points[] = p;
  52.  
  53. sort(points+, points+n, comp);
  54.  
  55. stack[] = points[];
  56. stack[] = points[];
  57. top = ;
  58.  
  59. for (i=; i<n; ++i) {
  60. while(top && cross(stack[top-], stack[top], points[i])<=)
  61. --top;
  62. stack[++top] = points[i];
  63. }
  64. }
  65.  
  66. int main() {
  67. int t, case_n;
  68. int n;
  69. int i, j, k;
  70. Point_t p;
  71.  
  72. #ifndef ONLINE_JUDGE
  73. freopen("data.in", "r", stdin);
  74. #endif
  75.  
  76. scanf("%d", &t);
  77. while (t--) {
  78. scanf("%d %d", &case_n, &n);
  79. for (i=; i<n; ++i)
  80. scanf("%d %d", &points[i].x, &points[i].y);
  81. Graham(n);
  82. printf("%d %d\n", case_n, top+);
  83. p = stack[];
  84. k = ;
  85. for (i=; i<=top; ++i) {
  86. if (stack[i].y>p.y || (stack[i].y==p.y && stack[i].x<p.x)) {
  87. p = stack[i];
  88. k = i;
  89. }
  90. }
  91. for (i=k; i>=; --i)
  92. printf("%d %d\n", stack[i].x, stack[i].y);
  93. for (i=top; i>k; --i)
  94. printf("%d %d\n", stack[i].x, stack[i].y);
  95. }
  96.  
  97. return ;
  98. }

【HDOJ】3285 Convex Hull of Lattice Points的更多相关文章

  1. 【HDU 3662】3D Convex Hull

    http://acm.hdu.edu.cn/showproblem.php?pid=3662 求给定空间中的点的三维凸包上有多少个面. 用增量法,不断加入点,把新加的点能看到的面都删掉,不能看到的面与 ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  4. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  5. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  8. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  9. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

随机推荐

  1. Lucene多字段搜索

    最近在学习Lucene的过程中遇到了需要多域搜索并排序的问题,在网上找了找,资料不是很多,现在都列出来,又需要的可以自己认真看看,都是从其他网站粘贴过来的,所以比较乱,感谢原创的作者们!     使用 ...

  2. 玩转OpenStack网络Neutron(2)--使用Open vSwitch实现VLAN类型租户网络

    欢迎转载,转载请保留原作者信息 欢迎交流学习,共同进步! 作者:颜海峰 个人博客:http://yanheven.github.io 微博:海峰_云计算 http://weibo.com/344736 ...

  3. Swoole源代码学习记录(十五)——Timer模块分析

    swoole版本号:1.7.7-stable Github地址:点此查看 1.Timer 1.1.swTimer_interval_node 声明: // swoole.h 1045-1050h ty ...

  4. [CSS3] CSS :target Selector

    The :target selector allows us to interact with a fragment identifier, or hash, in our URL from CSS. ...

  5. Android之开发常用颜色

    Android开发中常常要用一些个性化的颜色,然而茫茫的RBG颜色对照表,往往给人眼花缭乱的感觉,更别说从中轻易选出一两种比较满意的颜色,下面我就总结一下开发中常用到的比较绚丽的颜色,都是有名有姓的哦 ...

  6. Java基础知识强化之集合框架笔记03:Collection集合的功能概述

    1. Collection功能概述:Collection是集合的顶层接口,它子体系有重复的,有唯一性,有有序的,无序的. (1)添加功能 boolean add(Object obj):添加一个元素 ...

  7. 自己编写SqlHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  8. jquery的ajax方法:ajaxStart()和ajaxStop()

    ajaxStart()方法: 当AJAX请求开始时,显示加载中的提示. $("#divMessage").ajaxStart(function(){ $(this).show(); ...

  9. Android项目代码混淆

    http://coolshell.info/blog/2015/03/Android-studio-prefrence.html 什么是Gradle Gradle是一种依赖管理工具,基于Groovy语 ...

  10. Sql Xtype

    SQL Server xtype的介绍   在数据库内创建的每个对象(约束.默认值.日志.规则.存储过程等)在表中占一行.只有在 tempdb 内,每个临时对象才在该表中占一行.  列名 数据类型 描 ...