【51NOD】斜率最大
【题解】通过画图易得结论:最大斜率一定出现在相邻两点之间。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=;
const double eps=1e-;
struct cyc{int x,y,ord;}a[maxn];
int b[maxn],n;
bool cmp(cyc a,cyc b)
{return a.x<b.x;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){scanf("%d%d",&a[i].x,&a[i].y);a[i].ord=i;}
sort(a+,a+n+,cmp);
int tot=;
double ans=;
for(int i=;i<n;i++)
{
double anss=(a[i+].y-a[i].y)/(a[i+].x-a[i].x);
if(anss>ans)ans=anss,tot=;
if(anss+eps>ans&&anss-eps<ans)b[++tot]=i;
}
for(int i=;i<=tot;i++)
{
printf("%d %d\n",a[b[i]].ord,a[b[i]+].ord);
}
return ;
}
【51NOD】斜率最大的更多相关文章
- 51Nod P1100 斜率最大
传送门: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 由于2 <= N <= 10000, 所以 ...
- 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 1100】斜率最大
Description 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点. (点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标 ...
- 51Nod - 1107 斜率小于0的连线数量
二维平面上N个点之间共有C(n,2)条连线.求这C(n,2)条线中斜率小于0的线的数量. 二维平面上的一个点,根据对应的X Y坐标可以表示为(X,Y).例如:(2,3) (3,4) (1,5) (4, ...
- 51nod 1107 斜率小于零连线数量 特调逆序数
逆序数的神题.... 居然是逆序数 居然用逆序数过的 提示...按照X从小到大排列,之后统计Y的逆序数... 之后,得到的答案就是传说中的解(斜率小于零) #include<bits/stdc+ ...
- 51nod 1100 斜率最大
可以用三个点简单证明斜率最大的直线两个点! #include <bits/stdc++.h> #define MAXN 10010 using namespace std; struct ...
- 51nod 1488 帕斯卡小三角 斜率优化
思路:斜率优化 提交:\(2\)次 错因:二分写挂 题解: 首先观察可知, 对于点\(f(X,Y)\),一定是由某个点\((1,p)\),先向下走,再向右下走. 并且有个显然的性质,若从\((1,p) ...
- 51nod1100(计算斜率)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 题意:中文题啦- 思路:算斜率不用多说吧?本题唯一一个 ...
随机推荐
- Why is setTimeout(fn, 0) sometimes useful?
http://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful jquery validation s ...
- HBase 所有命令解析
COMMAND GROUPS:Group name: generalCommands: status, table_help, version, whoami Group name: ddlComma ...
- C# lamda表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- [OS] 多线程--原子操作 Interlocked系列函数
转自:http://blog.csdn.net/morewindows/article/details/7429155 上一篇<多线程--第一次亲密接触 CreateThread与_begint ...
- [转]MATLAB cell数据类型
细胞型数据类型(cell)使不同类型和不同维数的数组可以共存,细胞型数组实际上可以认为是一种以任意形式的数组为分量的多维数组. 1.细胞型数据的定义 1)直接赋值定义:细胞型变量在定义时需要使用大括号 ...
- 【bzoj2100】[Usaco2010 Dec]Apple Delivery 最短路
题目描述 Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she tr ...
- C# 面向对象——继承
继承:代码文字结合理解 class Program { static void Main(string[] args) { //Student s = new Student(); //Driver ...
- P1491 集合位置
题目描述 每次有大的活动,大家都要在一起“聚一聚”,不管是去好乐迪,还是避风塘,或者汤姆熊,大家都要玩的痛快.还记得心语和花儿在跳舞机上的激情与释放,还记得草草的投篮技艺是如此的高超,还记得狗狗的枪法 ...
- [CF1095F]Make It Connected
题目大意:给你$n(n\leqslant2\times10^5)$个点和$m(m\leqslant2\times10^5)$条边,第$i$个点点权为$a_i$.连接$u,v$两个点的代价为$a_u+a ...
- Codeforces Round #466 (Div. 2) E. Cashback
Codeforces Round #466 (Div. 2) E. Cashback(dp + 贪心) 题意: 给一个长度为\(n\)的序列\(a_i\),给出一个整数\(c\) 定义序列中一段长度为 ...