NYOJ 78 圈水池(凸包基础)@
来源:互联网 发布:淘宝快递拒签运费谁负 编辑:程序博客网 时间:2024/04/30 14:06
圈水池
时间限制:3000 ms | 内存限制:65535 KB
难度:4
- 描述
- 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来,以防止不是自己的牲畜来喝水,各个水池都标有各自的坐标,现在要你写一个程序利用最短的篱笆将这些供水装置圈起来!(篱笆足够多,并且长度可变)
- 输入
- 第一行输入的是N,代表用N组测试数据(1<=N<=10)
第二行输入的是m,代表本组测试数据共有m个供水装置(3<=m<=100)
接下来m行代表的是各个供水装置的横纵坐标 - 输出
- 输出各个篱笆经过各个供水装置的坐标点,并且按照x轴坐标值从小到大输出,如果x轴坐标值相同,再安照y轴坐标值从小到大输出
- 样例输入
140 01 12 33 0
- 样例输出
0 02 33 0
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <vector>using namespace std;typedef long long LL;const LL mod = 1e9+7;const int N = 110;struct node{ int x, y; node operator -(const node& tmp)const { node e; e.x=x-tmp.x, e.y=y-tmp.y; return e; } int operator *(const node& tmp)const { return x*tmp.y-y*tmp.x; } bool operator <(const node& tmp)const { return x<tmp.x||(x==tmp.x&&y<tmp.y); }}p[N], s[N];int cmp(node a,node b){ if(a.x!=b.x) return a.x<b.x; return a.y<=b.y;}int judge(node a,node b,node c){ return (b-a)*(c-a)>0;}int main(){ int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); for(int i=0;i<n;i++) { scanf("%d %d", &p[i].x, &p[i].y); } sort(p,p+n,cmp); int top=0; for(int i=0;i<n;i++) { while(top>=2&& !judge(s[top-2],s[top-1],p[i])) top--; s[top++]=p[i]; } int t=top-1; for(int i=n-1;i>=0;i--) { while(top>=t+2&& !judge(s[top-2],s[top-1],p[i])) top--; s[top++]=p[i]; } --top; sort(s,s+top); for(int i=0;i<top;i++) printf("%d %d\n",s[i].x, s[i].y); } return 0;}
0 0
- NYOJ 78 圈水池(凸包基础)@
- NYOJ 圈水池(凸包问题)
- NYOJ 78 圈水池( 凸包入门)
- 【解题报告】 NYOJ 78 -- 圈水池 Andrew 凸包算法
- nyoj 78 圈水池 凸包问题 篱笆问题
- 凸包[nyoj 78 圈水池]
- NYOJ 78 圈水池 (凸包输出路径)
- nyoj 圈水池 78 (二维凸包 数学几何) 凸包入门
- 圈水池(凸包)
- NYOJ-78:圈水池
- nyoj 78 圈水池
- nyoj 78 圈水池
- 圈水池(nyoj 78)
- NYOJ 78 圈水池
- NYOJ 78 圈水池
- NYOJ 78 - 圈水池
- 凸包问题(圈水池)
- NYIST78-圈水池(凸包)
- FZU1894-志愿者选拔
- 性能测试7-性能调优
- 图的基本存储的基本方式一
- 中国的创新经济—学习笔记1
- 项目人力资源管理 考纲与考试要点
- NYOJ 78 圈水池(凸包基础)@
- Android基于RecyclerView实现高亮搜索列表
- linux之进程间通信--使用信号
- Windows PowerShell基本语法及常用命令
- 加快AndroidStudio运行速度的方法
- 416. Partition Equal Subset Sum
- 观察者模式--C++
- 机器学习笔记 - 剪枝处理
- theano scan arange shape 实例