【51nod 1100】斜率最大
Description
Input
第1行,一个数N,N为点的数量。(2 <= N <= 10000)
第2 - N + 1行:具体N个点的坐标,X Y均为整数(-10^9 <= X,Y <= 10^9)
Output
每行2个数,中间用空格分隔。分别是起点编号和终点编号(起点的X轴坐标 < 终点的X轴坐标)
Input示例
5
1 2
6 8
4 4
5 4
2 3
Output示例
4 2
证明最优解一定是在相邻两个点之间。
然后顺便感慨一下,隔壁O(n2)的暴力居然过了……目瞪口呆。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
struct node{int x,y,num;}a[];
int n,cnt,t=,ans[];
double lv=-2e9;
bool cmp(node a,node b){return a.x<b.x;}
int comp(double i,double j)
{
if(fabs(i-j)<1e-)return ;
if(i>j)return ;
return -;
}
double xl(int i,int j){return (double)(a[j].y-a[i].y)/(a[j].x-a[i].x);}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].num=i;
}
sort(a+,a+n+,cmp);
while(t<=n)
{
double f=xl(t-,t);
if(comp(f,lv)>){lv=f;cnt=;ans[++cnt]=t-;ans[++cnt]=t;}
else if(comp(f,lv)==)ans[++cnt]=t;
t++;
while(t<=n&&comp(xl(t-,t-),xl(t-,t))>)t++;
}
for(int i=;i<=cnt;i++)printf("%d ",a[ans[i]].num);
return ;
}
【51nod 1100】斜率最大的更多相关文章
- 51nod 1100 斜率最大
可以用三个点简单证明斜率最大的直线两个点! #include <bits/stdc++.h> #define MAXN 10010 using namespace std; struct ...
- 51 Nod 1100 斜率最大
1100 斜率最大 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线 ...
- 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) ...
随机推荐
- [HAOI2015]树上染色(树形背包)
有一棵点数为 N 的树,树边有边权.给你一个在 0~ N 之内的正整数 K ,你要在这棵树中选择 K个点,将其染成黑色,并将其他 的N-K个点染成白色 . 将所有点染色后,你会获得黑点两两之间的距离加 ...
- hdu 1238 Substrings(kmp+暴力枚举)
Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...
- 20165223 实验四 Android开发基础
实验四 Android开发基础 目录 一.实验报告封面 二.具体实验内容 (一)Android Stuidio的安装测试 (二)Activity测试 (三)UI测试 (四)布局测试 (五)教材代码测试 ...
- Windows系统服务管理
1.用SC命令管理: 启动redis服务: C:\Users\Administrator>sc start redis 停止redis服务: C:\Users\Administrator> ...
- Spring Boot实战
Spring在java EE开发中是实际意义上的标准,但我们在开发Spring的时候可能会遇到以下令人头疼的问题: 1.大量配置文件的定义.2.与第三方软件整合的技术问题. Spring每个版本的退出 ...
- A1139. First Contact
Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle i ...
- RGBColorspace 与 GRAYColorspace 图片混合后,生成的视频有点问题
最近有一个用户遇到一个情况: 有3张图片,其中前两张是 RGBColorspace,最后一张是 GrayColorspace: 生成的视频,在显示最后一张图片的时候,明显出现奇怪的色彩区域,看下图: ...
- 为什么要用PolyFill(JS中的修补匠)
var users = [{name:"zhangsan",age:18},{name:"jack",age:20}]; 这是一个对象数组.如果我们要查询名字为 ...
- Unity 摄像机跟随
方式一:将摄像机直接拖到游戏对象的下面: 方式二:脚本实现 using System.Collections; using System.Collections.Generic; using Unit ...
- (贪心和优先队列) POJ1862 Stripies
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21506 Accepted: 9478 Descrip ...