题目链接

 /*
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算法求凸包)的更多相关文章

  1. NYOJ 78 圈水池 (入门级凸包)

    题目链接:nyoj 78  单调链凸包小结 题目讲解:本题考查的主要是凸包的用法,算是入门级的吧,当然前提是你接触过,平面几何: AC代码: #include<iostream> #inc ...

  2. 题解报告:NYOJ #78 圈水池(打印凸包顶点)

    描述: 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来,以防止不是自己的牲畜来喝水,各个水池都标有各自的坐标,现在要你写一个程序利用最短的篱笆将这些供水装置圈起来!( ...

  3. nyoj 78:圈水池 【凸包入门】

    题目链接 将所有点按从左至右顺序排序,然后将所有点先从左到右扫描再从右到左扫描,逐渐将凸包轮廓“勾勒”出来 (凸包轮廓满足,轮廓上连续的三个点按先后顺序给出的话呈逆时针方向) 最后删去一个重复的起(终 ...

  4. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  5. nyist 78 圈水池

    http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 有一个 ...

  6. (模板)graham扫描法、andrew算法求凸包

    凸包算法讲解:Click Here 题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是 ...

  7. (模板)poj1113(graham扫描法求凸包)

    题目链接:https://vjudge.net/problem/POJ-1113 题意:简化下题意即求凸包的周长+2×PI×r. 思路:用graham求凸包,模板是kuangbin的. AC code ...

  8. 关于graham扫描法求凸包的小记

    1.首先,凸包是啥: 若是在二维平面上,则一般的,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有的点. ───────────────────────────── ...

  9. Graham扫描法 --求凸包

    前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来.当这个多边形是凸多边形的时候,我们就叫它“凸包”.如下图:  然后,什么是凸包 ...

随机推荐

  1. node.js及node-inspector的调试方法

    1.先运行 $ node --debug-brk test.js 2.再在新的窗口运行: $ node-inspector 3.再打开Chrome浏览器输入node-inspector提示的地址,就会 ...

  2. 交换机/路由器上的 S口 F口 E口

    S口是serial接口的意思,也叫高速异步串口,主要是连接广域网的V.35线缆用的,说白了就是路由器和路由器连接时候用的,可以用命令设置带宽,一般也就在10M.8M左右.F口是FastEthernet ...

  3. Vue:实践学习笔记(3)——组件使用

    Vue:实践学习笔记(3)——组件使用 全局注册 1.注册组件 Vue.component('my-component',{ //选项 }) 说明:my-component就是注册的组件自定义的标签名 ...

  4. storage

    localStorage(本地存储),可以长期存储数据,没有时间限制,一天,一年,两年甚至更长,数据都可以使用. sessionStorage(会话存储),只有在浏览器被关闭之前使用,创建另一个页面时 ...

  5. iOS 11 Xcode9开发 新特性学习 (新方法篇)

    1 .  引入github (1) 在Xcode 9 中,引入了 gitHub,新源代码管理导航器 可以展示branch分支和 tag标签. (2)点进去,就可以看指定一次commit了哪些东西 2 ...

  6. Ajax在jQuery中的应用---加载异步数据

    Ajax是Asynchronous JavaScript and XML的缩写,其核心是通过XMLHttpRequest对象,以一种异步的方式,向服务器发送数据请求,并通过该对象接收请求返回的数据,从 ...

  7. Hibernate多对多关联

    多对多关联: 示例:Teacher和Student,一个Teacher可以教很多student,一个Student也可以被很多teacher教   多对多单向关联 Teacher知道自己教了哪些学生, ...

  8. php大转盘抽奖

    抽奖大转盘演示:http://www.sucaihuo.com/php/3301.html function getRand($proArr, $proCount) { $result = ''; $ ...

  9. curl操作封装

    <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $url 请求的url ...

  10. mongodb中的__v字段

    "__v"是"versionKey"的简写,当每一个文档由mongoose创建时就会自动添加,代表这该文档的版本,此属性可配置修改,默认为"__v&q ...