凸包模板题目。

 /* 3285 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 55 typedef struct {
int x, y;
} Point_t; Point_t points[MAXN];
Point_t stack[MAXN];
int top; void output(int); double dist(Point_t a, Point_t b) {
return sqrt(1.0*(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} int dist2(Point_t a, Point_t b) {
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int cross(Point_t a, Point_t b, Point_t c) {
return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
} bool comp(Point_t a, Point_t b) {
int m = cross(points[], a, b);
return m> || (m== && dist2(points[], a)<dist2(points[], b));
} void Graham(int n) {
Point_t p;
int i, j, k; p = points[];
k = ;
for (i=; i<n; ++i) {
if (points[i].x<p.x || (points[i].x==p.x && points[i].y<p.y)) {
p = points[i];
k = i;
}
}
points[k] = points[];
points[] = p; sort(points+, points+n, comp); stack[] = points[];
stack[] = points[];
top = ; for (i=; i<n; ++i) {
while(top && cross(stack[top-], stack[top], points[i])<=)
--top;
stack[++top] = points[i];
}
} int main() {
int t, case_n;
int n;
int i, j, k;
Point_t p; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %d", &case_n, &n);
for (i=; i<n; ++i)
scanf("%d %d", &points[i].x, &points[i].y);
Graham(n);
printf("%d %d\n", case_n, top+);
p = stack[];
k = ;
for (i=; i<=top; ++i) {
if (stack[i].y>p.y || (stack[i].y==p.y && stack[i].x<p.x)) {
p = stack[i];
k = i;
}
}
for (i=k; i>=; --i)
printf("%d %d\n", stack[i].x, stack[i].y);
for (i=top; i>k; --i)
printf("%d %d\n", stack[i].x, stack[i].y);
} return ;
}

【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. App列表之分组ListView

    吸引用户的眼球,是我们至死不渝的追求:      第一时间呈现最有价值的信息,简明大方,告诉客户,你的选择是多么的明智,这正是你寻觅已久的东西. 分组的应用场合还是很多的,有数据集合的地方往往要分组显 ...

  2. CreateThread函数

    当使用CreateProcess调用时,系统将创建一个进程和一个主线程. CreateThread将在主线程的基础上创建一个新线程,大致做例如以下步骤: 1在内核对象中分配一个线程标识/句柄,可供管理 ...

  3. Open-source Project官方地址

    非常遗憾因为这篇博文是专门搜集各个开源项目的各种官方连接地址的,所以链接较多,csdn不同意保存. 请点击这里下载. 因为我的积分不多了,所以这个文档须要一个积分..应该不多吧...确实没有积分的童鞋 ...

  4. [Angular 2] @ngrx/devtools demo

    Check the Github: https://github.com/ngrx/devtools Example:

  5. android bitmap的 一些简单操作

    /** 获取 drawable 的图片 可以循环 1.图名 2.drawable 3.包名 **/ int imgid = getResources().getIdentifier("ic_ ...

  6. 【iOS】3D Touch

    文章内容来源于Apple的开发者文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptu ...

  7. 多线程(NSThread、NSOperation、GCD)编程浅谈

    一.基本概念 进程:一个具有一定独立功能的程序关于某个数据集合的一次运行活动.可以理解成一个运行中的应用程序.线程:程序执行流的最小单元,线程是进程中的一个实体.同步:只能在当前线程按先后顺序依次执行 ...

  8. EventBus 事件总线 原理

    原理 一句话描述:register会把当前类中匹配的方法,存入一个map,而post会根据实参去map查找进行反射调用 撇开专业术语,其实EventBus就是在内部[存储]了一堆onEvent开头的方 ...

  9. JavasScript基数排序

    基数排序   91, 46, 85, 15, 92, 35, 31, 22经过基数排序第一次扫描之后, 数字被分配到如下盒子中:Bin 0:Bin 1: 91, 31Bin 2: 92, 22Bin ...

  10. ASP.NET的WebConfig

    转:http://blog.csdn.net/q3498233/article/details/8137364 WebConfig 花了点时间整理了一下ASP.NET Web.config配置文件的基 ...