nyoj-78-圈水池(Graham算法求凸包)
/*
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 ;
}
nyoj-78-圈水池(Graham算法求凸包)的更多相关文章
- NYOJ 78 圈水池 (入门级凸包)
题目链接:nyoj 78 单调链凸包小结 题目讲解:本题考查的主要是凸包的用法,算是入门级的吧,当然前提是你接触过,平面几何: AC代码: #include<iostream> #inc ...
- 题解报告:NYOJ #78 圈水池(打印凸包顶点)
描述: 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来,以防止不是自己的牲畜来喝水,各个水池都标有各自的坐标,现在要你写一个程序利用最短的篱笆将这些供水装置圈起来!( ...
- nyoj 78:圈水池 【凸包入门】
题目链接 将所有点按从左至右顺序排序,然后将所有点先从左到右扫描再从右到左扫描,逐渐将凸包轮廓“勾勒”出来 (凸包轮廓满足,轮廓上连续的三个点按先后顺序给出的话呈逆时针方向) 最后删去一个重复的起(终 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- nyist 78 圈水池
http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个 ...
- (模板)graham扫描法、andrew算法求凸包
凸包算法讲解:Click Here 题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是 ...
- (模板)poj1113(graham扫描法求凸包)
题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是kuangbin的. AC code ...
- 关于graham扫描法求凸包的小记
1.首先,凸包是啥: 若是在二维平面上,则一般的,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有的点. ───────────────────────────── ...
- Graham扫描法 --求凸包
前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图: 然后,什么是凸包 ...
随机推荐
- mysql数据库补充知识4 数据备份和pymysql模块
一 介绍 #注意: 批量加注释:ctrl+?键 批量去注释:ctrl+shift+?键 二 MySQL数据备份 #1. 物理备份: 直接复制数据库文件,适用于大型数据库环境.但不能恢复到异构系统中如W ...
- Java - 在控制台中执行一个可执行jar
1.Maven打包一个可执行jar: <build> <plugins> <plugin> <groupId>org.apache.maven.plug ...
- Manacher专题
1.POJ 3974 Palindrome 题意:求一个长字符串的最长回文子串. 思路:Manacher模板. #include<iostream> #include<algorit ...
- vimium的使用介绍和基本用法
vimium是chrome浏览器的一个插件,fq去chrome应用商店搜索vimium,下载安装 纯键盘操作,脱离了鼠标,提高效率 核心是f,安装好vimium后只需要按f,输入对应的编号就能进入相应 ...
- java 图片Base64字符串转图片二进制数组
public static byte[] base64ToImgByteArray(String base64) throws IOException{ sun.misc.BASE64Decoder ...
- Linux文件系统管理 挂载命令mount
概述 mount命令用来挂载Linux系统外的文件. Linux 中所有的存储设备都必须挂载之后才能使用,包括硬盘.U 盘和光盘(swap 分区是系统直接调用的,所以不需要挂载).不过,硬盘分区在安装 ...
- Raspberry Pi开发之旅-实现云平台监控
一.基本设置 1 sudo raspi-config 移动到第五项“Enable Camera”,回车进入,按tab键切换到“Enable”回车确认.回到主菜单,tab键切换到“Finish”回车确认 ...
- QtGstreamer 编译
一 安装依赖项 1 安装cmake hdhuang@hdh-UBT:~/gstreamer/qt-gstreamer-0.10.2/build$ sudo apt-get install cmake ...
- MongoDB快速入门(九)- 投影
MongoDB投影 mongodb投影意义是只选择需要的数据,而不是选择整个一个文档的数据.如果一个文档有5个字段,只需要显示3个,只从中选择3个字段. MongoDB的find()方法,解释了Mon ...
- struts2实现文件的上传和下载实例[转]
实现原理 Struts 2是通过Commons FileUpload文件上传. Commons FileUpload通过将HTTP的数据保存到临时文件夹,然后Struts使用fileUpload拦截器 ...