51nod 1100 斜率最大
可以用三个点简单证明斜率最大的直线两个点!
#include <bits/stdc++.h>
#define MAXN 10010
using namespace std;
struct Node{
int x, y, number;
}gg[MAXN];
bool cmp(Node a, Node b){
return a.x<b.x;
}
int main(void){
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> gg[i].x >> gg[i].y;
gg[i].number=i+1;
}
sort(gg, gg+n, cmp);
queue<int> node1, node2;
double cnt=0, cc=0;
for(int i=1; i<n; i++){
cnt=(gg[i].y-gg[i-1].y)*1.0/(gg[i].x-gg[i-1].x);
if(cnt>cc){
cc=cnt;
while(!node1.empty()){
node1.pop();
}
while(!node2.empty()){
node2.pop();
}
node1.push(gg[i-1].number);
node2.push(gg[i].number);
}else if(cnt==cc){
node1.push(gg[i-1].number);
node2.push(gg[i].number);
}
}
while(!node1.empty()){
cout << node1.front() << " " << node2.front() << endl;
node1.pop();
node2.pop();
}
return 0;
}
51nod 1100 斜率最大的更多相关文章
- 51 Nod 1100 斜率最大
1100 斜率最大 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线 ...
- 【51nod 1100】斜率最大
Description 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点. (点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标 ...
- 51Nod P1100 斜率最大
传送门: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 由于2 <= N <= 10000, 所以 ...
- 51Nod - 1107 斜率小于0的连线数量
二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4, ...
- 【51NOD】斜率最大
[题解]通过画图易得结论:最大斜率一定出现在相邻两点之间. #include<cstdio> #include<algorithm> #include<cstring&g ...
- 51nod 1107 斜率小于零连线数量 特调逆序数
逆序数的神题.... 居然是逆序数 居然用逆序数过的 提示...按照X从小到大排列,之后统计Y的逆序数... 之后,得到的答案就是传说中的解(斜率小于零) #include<bits/stdc+ ...
- 51NOD——N 1107 斜率小于0的连线数量
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 ...
- 51nod 1451 合法三角形 判斜率去重,时间复杂度O(n^2)
题目: 这题我WA了3次,那3次是用向量求角度去重算的,不知道错在哪了,不得不换思路. 第4次用斜率去重一次就过了. 注意:n定义成long long,不然求C(3,n)时会溢出. 代码: #incl ...
- 51nod 1488 帕斯卡小三角 斜率优化
思路:斜率优化 提交:\(2\)次 错因:二分写挂 题解: 首先观察可知, 对于点\(f(X,Y)\),一定是由某个点\((1,p)\),先向下走,再向右下走. 并且有个显然的性质,若从\((1,p) ...
随机推荐
- CentOS 5.11安装配置LAMP服务器(Apache+PHP5+MySQL)
http://www.osyunwei.com/archives/8880.html 准备篇: CentOS 5.x系统安装配置图解教程 http://www.osyunwei.com/archive ...
- [Angular] Modify User Provided UI with Angular Content Directives
If we’re going to make our toggle accessible, we’ll need to apply certain aria attributes to the con ...
- Angular团队公布路线图,并演示怎样与React Native集成
本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2015/06/angular-2-react-native-roadmap 前不久在旧 ...
- 相机标定(Camera calibration)
简单介绍 摄像机标定(Camera calibration)简单来说是从世界坐标系换到图像坐标系的过程.也就是求终于的投影矩阵 P 的过程,以下相关的部分主要參考UIUC的计算机视觉的课件(网址Spr ...
- 基于空间直方图meanshift跟踪
近期看了一篇文章<spatiograms versus histograms for region-based tracking>,在此把这篇文章的核心思想及算法推理进行整理. 空间直方图 ...
- WHU-1551-Pairs(莫队算法+分块实现)
Description Give you a sequence consisted of n numbers. You are required to answer how many pairs of ...
- linux document and directory find
http://suchalin.blog.163.com/blog/static/55304677201062924959497/ Linux 查看文件夹大小及文件数量命令 2010-07-29 14 ...
- MVC架构在游戏开发中的应用
一 定义 MVC即Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写. MVC是一种"前端"的设计模式. MV ...
- ubuntu安装jdk 1.6
linux下安装JDK1.6 1. 去http://java.sun.com/j2se/1.4.2/download.html 下载一个Linux Platform的JDK,建议下载RPM自解压格式的 ...
- Golang1.8编译静态库给C使用
Go实例代码: package main import ( "fmt" ) import "C" //export Printf func Printf(for ...