题目链接

 /*
Name:nyoj-78-圈水池
Copyright:
Author:
Date: 2018/4/27 9:52:48
Description:
Graham求凸包
zyj大佬的模板,改个输出就能用
*/
#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct point{
double x, y;
};
bool mult(point sp, point ep, point op){ //叉积
return (sp.x - op.x) * (ep.y - op.y) >= (ep.x - op.x) * (sp.y - op.y);
}
inline bool operator < (const point &l, const point &r){
return l.y < r.y || (l.y == r.y && l.x < r.x);
}
int graham(int n, point pnt[], point res[]){
int i, len, top = ;
sort(pnt, pnt + n);//排序找最小的点
if (n == ){
return ;
}
res[] = pnt[];
if (n == ){
return ;
}
res[] = pnt[];
if (n == ){
return ;
}
res[] = pnt[];
for (i = ; i < n; i++){
while (top && mult(pnt[i], res[top], res[top - ])){
top--;
}
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - ];
for (i = n - ; i >= ; i--){
while (top != len && mult(pnt[i], res[top], res[top - ])){
top--;
}
res[++top] = pnt[i];
}
return top; // 返回凸包中点的个数
}
bool cmp(const point &l, const point &r){
return l.x < r.x || (l.x == r.x && l.y < r.y);
}
int main()
{
int t;
cin>>t;
point pnt[], res[];
while (t--) {
memset(res, , sizeof(res));
memset(pnt, , sizeof(pnt));
int m;
cin>>m;
for (int i=; i<m; i++)
cin>>pnt[i].x>>pnt[i].y;
int ct = graham(m, pnt, res);
sort(res, res + ct, cmp);
for (int i=; i<ct; i++) {
printf("%.0f %.0f\n", res[i].x, res[i].y);
}
}
return ;
}

最新文章

  1. H5手机端关注的问题
  2. filter 简介
  3. bootstrap学习笔记之三(组件的使用)
  4. fasta文件拆分与合并
  5. HashSet中的元素必须重写equals方法和hashCode方法
  6. POJ 1159
  7. zoj1074 To the Max
  8. 属性“dataProvider”有多个初始值设定项。(注意:“dataProvider”是“mx.charts.BarChart”的默认属性)。
  9. LAMP_yum安装
  10. 学号:201621123032 《Java程序设计》第1周学习总结
  11. 剑指Offer——腾讯+360+搜狗校招笔试题+知识点总结
  12. BZOJ3626[LNOI2014]LCA——树链剖分+线段树
  13. Android手机特殊软件配置
  14. 支付宝 net
  15. Python实现图片压缩
  16. spring框架中的注解
  17. 第一章 HTML基本标签
  18. python分割txt文件
  19. 前端学习 -- Css -- 定义列表
  20. .NET 4并行编程入门之Task的取消[转]

热门文章

  1. (转)js获取内网ip地址,操作系统,浏览器版本等信息
  2. POSIX相关概念
  3. Protobuf支持 pointf
  4. 合并apk和odex 为完整的apk安装文件
  5. OpenGL学习进程(5)第三课:视口与裁剪区域
  6. 配置NFS作为HDFS高可用的共享存储系统
  7. 【Tech】CAS RESTful API使用笔记
  8. 字符串哈希小结(BKDR,RK)
  9. IDEA使用前的各种基本设置(转)
  10. Linux挂载第二块硬盘操作方法