【HDOJ】3285 Convex Hull of Lattice Points
凸包模板题目。
/* 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的更多相关文章
- 【HDU 3662】3D Convex Hull
http://acm.hdu.edu.cn/showproblem.php?pid=3662 求给定空间中的点的三维凸包上有多少个面. 用增量法,不断加入点,把新加的点能看到的面都删掉,不能看到的面与 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- Dump 文件生成与分析
近期两天因为项目的须要,研究了一下Dump文件相关的知识,今天做一个小节(因为研究不久而且第一次写blog,希望网友们看到不要见笑). Dump文件是进程的内存镜像.能够把程序的运行状态通过调试器保存 ...
- SCI科技论文写作技巧-核心价值
第一次写SCI论文写作技巧,本身不是大牛,也许没有资金格谈论这个. 这里仅仅是一些个人思考,不正确,好还是不好.而当另一种理论. 对于工程专业的学生,谁往往应用,书写SCI事情.当然,也不是没可能.全 ...
- python一些技巧
1. 使用目录管理 sys.path.append(sys.argv[0][:sys.argv[0].rfind('com'+os.sep+'abc')]) from com.abc.libs imp ...
- 从 ReactiveCocoa 中能学到什么?不用此库也能学以致用
从知道ReactiveCocoa开始就发现对这个库有不同的声音,上次参加<T>技术沙龙时唐巧对在项目中已全面使用FRP的代码家提出为什么这种编程模型出现了这么长时间怎么像ReactiveC ...
- iOS图片拉伸
常用的图片拉伸场景有:聊天页面的气泡,需要根据内容拉伸,但圆角拉伸后会变形,为避免圆角拉伸,可以指定拉伸区域.UIImage实体调用以下方法即可指定拉伸区域. - (UIImage *)stretch ...
- HDU5317
题意:定义一个数K,最小质因数形式为K = a*b*c形式(如12 = 2*2*3),相同只取一个(所以12只能取2,3两个,既F[12]=2)给L,R区间,找出区间内最大的F[x](L<=x& ...
- jQueryUI 日期控件
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inse ...
- editplus双击单词语法高亮显示设置
view=>Word Highlighting
- eclise -The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
在做arcgis android开发的时候,突然遇到这种错误,The method onClick(View) of type new View.OnClickListener(){} must ov ...
- 网络流转换为Byte数组
/// <summary> /// 网络流转换为Byte数组 /// </summary> /// <param name="stream">& ...