NYOJ-253 凸包
LK的旅行
- 描述
-
LK最近要去某几个地方旅行,她从地图上计划了几个点,并且用笔点了出来,准备在五一假期去这几个城市旅行。现在希望你找出她点的所有的点中距离最远的两个点的距离是多少。各个景点可以认为是在一个平面上。
- 输入
- 第一行有一个整数0<n<10表示测试数据的组数随后的n组数据中,第一行有一个整数3<m<100000表示有m个旅游景点。随后的m行每行有两个整数,分别表示每一个点的x和y。景点坐标中可能有重复的,0<=x,y<=10000)
- 输出
- 每组数据输出距离最远的点对的距离的平方.
- 样例输入
-
- 1
- 4
- 0 0
- 1 1
- 0 1
- 1 0
- 1
- 样例输出
-
- 2
代码:
- #include<iostream>
- #include<fstream>
- #include<algorithm>
- using namespace std;
- const int num=;
- int N;
- struct Point
- {
- int x;
- int y;
- }points[num],output[num];
- inline int ccw(Point p1,Point p2,Point p3) //交叉乘积
- {
- return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);
- }
- inline int dis(Point p1,Point p2) //距离
- {
- return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
- }
- int cmp(const void *po1,const void *po2) //排序用的比较函数
- {
- Point *p1=(Point *)po1;
- Point *p2=(Point *)po2;
- int temp=ccw(points[],*p1,*p2); //先判断方向
- if(temp>)
- {
- return -;
- }
- else if(temp<)
- {
- return ;
- }
- else
- {
- return dis(*p1,points[])-dis(*p2,points[]); //共线时按距离从大到校排序
- }
- }
- int maxDist( )
- {
- int min_index=;
- for(int i=;i<N;i++)
- {
- if(points[i].x<points[min_index].x)
- min_index=i;
- else if(points[i].x<points[min_index].x&&points[i].y<points[min_index].y)
- min_index=i;
- }
- swap(points[],points[min_index]); //找到y坐标最小的点,并交换到第一个位置
- qsort(points+,N-,sizeof(Point),cmp); //排序
- /* for(int i=0;i<N;i++)
- {
- printf("%d %d\n",points[i].x,points[i].y);
- }*/
- output[]=points[];
- output[]=points[];
- int top=;
- i=;
- while(i<N)
- {
- // printf("%d %d\n",points[i].x,points[i].y);
- int temp=ccw(output[top-],output[top],points[i]);
- if(temp>=)
- {
- output[++top]=points[i];
- i++;
- }
- /*else if(temp==0)
- {
- output[top]=points[i];
- i++;
- }*/
- else
- {
- top--;
- }
- }
- int maxD=;
- for( i=;i<=top;i++) //计算边界点之间的距离
- {
- // printf("%d %d\n",output[i].x,output[i].y);
- for(int j=i+;j<=top;j++)
- {
- int temp=dis(output[i],output[j]);
- if(temp>maxD)
- maxD=temp;
- }
- }
- printf("%d\n",maxD);
- return maxD;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--) //输入
- {
- scanf("%d",&N);
- for(int i=;i<N;i++)
- {
- scanf("%d %d",&points[i].x,&points[i].y);
- //printf("%d %d\n",points[i].x,points[i].y);
- }
- maxDist();
- }
- return ;
- }
- 2
NYOJ-253 凸包的更多相关文章
- 圈水池 nyoj 78 凸包算法
圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来,以防止不是自己的牲畜来喝水, ...
- nyoj 253:LK的旅行 【旋转卡壳入门】
题目链接 求平面最大点对. 找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板) 关于旋转卡壳算法 #include<bits/stdc++.h> using n ...
- NYOJ 78 圈水池 (入门级凸包)
题目链接:nyoj 78 单调链凸包小结 题目讲解:本题考查的主要是凸包的用法,算是入门级的吧,当然前提是你接触过,平面几何: AC代码: #include<iostream> #inc ...
- SGU 253 Theodore Roosevelt 快速判断点是否在凸包内
http://acm.sgu.ru/problem.php?contest=0&problem=253 题意简单易懂...给你n个点的凸包(经测试已经是极角序)...判断m个点是否在凸包内.. ...
- 题解报告:NYOJ #78 圈水池(打印凸包顶点)
描述: 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来,以防止不是自己的牲畜来喝水,各个水池都标有各自的坐标,现在要你写一个程序利用最短的篱笆将这些供水装置圈起来!( ...
- nyoj 78-圈水池 (凸包)
78-圈水池 内存限制:64MB 时间限制:3000ms 特判: No 通过数:5 提交数:6 难度:4 题目描述: 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来, ...
- nyoj 78:圈水池 【凸包入门】
题目链接 将所有点按从左至右顺序排序,然后将所有点先从左到右扫描再从右到左扫描,逐渐将凸包轮廓“勾勒”出来 (凸包轮廓满足,轮廓上连续的三个点按先后顺序给出的话呈逆时针方向) 最后删去一个重复的起(终 ...
- NYOJ-517 最小公倍数 TLE 分类: NYOJ 2013-12-29 14:49 253人阅读 评论(0) 收藏
#include <stdio.h> int main(){ int num[101]={0}; int result[21]={0}; int sum[101][21]={0}; int ...
- Monotone Chain Convex Hull(单调链凸包)
Monotone Chain Convex Hull(单调链凸包)算法伪代码: //输入:一个在平面上的点集P //点集 P 按 先x后y 的递增排序 //m 表示共a[i=0...m]个点,ans为 ...
- NYOJ 1007
在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...
随机推荐
- UserLogin
DAL: IUserDAL namespace Dal { /// <summary> /// This interface is defined for user functions. ...
- 定位表的数据块并且dump出来
SQL> select * from city; ID NAME ---------- ---------- 7 Chicago 6 Jers ...
- 4-2.矩阵乘法的Strassen算法详解
题目描述 请编程实现矩阵乘法,并考虑当矩阵规模较大时的优化方法. 思路分析 根据wikipedia上的介绍:两个矩阵的乘法仅当第一个矩阵B的列数和另一个矩阵A的行数相等时才能定义.如A是m×n矩阵和B ...
- windows2003服务器不显示桌面怎么办
ctrl +alt+delete 进入任务管理器应用程序里 创建新任务 C:\WINDOWS\explorer.exe 运行就行
- iOS常见问题(4)
一.非ARC内存管理问题. 有些同学在创建项目的时候忘记点ARC了,导致一些成员属性都莫名其妙的释放了.然后出现了一系列莫名其妙的错误. 在滚动UITableView的时候出现野指针错误. 一出现这些 ...
- SlimDx绘制点图元的问题
问题:点图元在自己创建的三维环境里渲染不出来,代码如下: GMCustomVertex.PositionNormalColored wellPart = new GMCustomVertex.Posi ...
- LintCode-Majority Number
Given an array of integers, the majority number is the number that occurs more than half of the size ...
- VS2010 配置opencv环境
大家在使用opencv的时候肯定会面对这样一个问题:根据官网以及大多数教程提供的方法中,似乎每一次新建一个opencv的新项目以后都需要重新再配置"VC++目录"中的"包 ...
- php发送get、post请求的几种方法
方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/'; $html = file_get_contents ...
- pos机套现是怎么回事
POS机是商家为了促进消费,向银行申请的刷卡机它的主要功能是转账就是通过客户的刷卡,把相对的金额转入商户的帐户银行会根据笔数或金额向商户收取手续费非法套现就是客户并未和商户产生贸易往来,单纯通过pos ...