http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100

首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有K(AC)<max(K(A,B),K(B,C));(K是斜率)

所以斜率一定会在相邻的两点中产生,排序O(nlogn),更新最大值O(n)。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1010
#define maxv 3000
#define mod 1000000000
using namespace std; struct point
{
int x,y,id;
bool operator < (const point a) const
{
return x<a.x;
}
}p[];
int main()
{
// freopen("a.txt","r",stdin);
int n,j,k;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id=i;
}
sort(p+,p+n+);
double ans=;
for(int i=;i<=n;i++)
{
if(p[i].y==p[i-].y) continue;
if((p[i].y-p[i-].y)*1.0/(p[i].x-p[i-].x)>ans)
{
ans=(p[i].y-p[i-].y)*1.0/(p[i].x-p[i-].x);
j=p[i].id;
k=p[i-].id;
}
}
printf("%d %d\n",k,j);
return ;
}

n个点中求任意两点组成斜率的最大值的更多相关文章

  1. AOJ GRL_1_C: All Pairs Shortest Path (Floyd-Warshall算法求任意两点间的最短路径)(Bellman-Ford算法判断负圈)

    题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C All Pairs Shortest Path Input ...

  2. 2018中国大学生程序设计竞赛 - 网络选拔赛 hdu Tree and Permutation 找规律+求任意两点的最短路

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  3. dfs+记忆化搜索,求任意两点之间的最长路径

    C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...

  4. LCA - 求任意两点间的距离

    There are n houses in the village and some bidirectional roads connecting them. Every day peole alwa ...

  5. hdu6446 网络赛 Tree and Permutation(树形dp求任意两点距离之和)题解

    题意:有一棵n个点的树,点之间用无向边相连.现把这棵树对应一个序列,这个序列任意两点的距离为这两点在树上的距离,显然,这样的序列有n!个,加入这是第i个序列,那么这个序列所提供的贡献值为:第一个点到其 ...

  6. 利用arguments求任意数量数字的和/最大值/最小值

    文章地址 https://www.cnblogs.com/sandraryan/ arguments是函数内的临时数据,用完销毁,有类似于数组的操作,但不是数组. 举个栗子1:利用arguments求 ...

  7. Floyed-Warshall算法(求任意两点间最短距离)

    思路:感觉有点像暴力啊,反正我是觉得很暴力,比如求d[i][j],用这个方法求的话,就直接考虑会不会经过点k(k是任意一点) ,最终求得最小值 看代码 #include<iostream> ...

  8. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  9. 使用DFS求任意两点的所有路径

    先上代码: public static void findAllPaths(Integer nodeId,Integer targetNodeId, Map<Integer,ArrayList& ...

随机推荐

  1. 安装CentOS--设置网络_1

    (1)在登录黑框中输入如下命令,让CentOS 7自动获取一个IP地址: # dhclient (2)正常情况下不会有任何输出内容.用如下命令查看获取到的IP地址: # ip addr 它将返回如图所 ...

  2. Objective -C Categories

    Objective -C Categories  The dynamic runtime dispatch mechanism employed by Objective-C lets you add ...

  3. 修改vim注释字体颜色

    vim /etc/vimrc#最后一行新增代码块hi comment ctermfg=6 注:注释用 " 标注 PS:默认的注释颜色是4  然后有0,1,2,3,4,5,6,7来选择.可以除 ...

  4. codevs 1082 线段树练习 3 --分块练习

    时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[ ...

  5. 模块 (Module)

    #1.模块概念的官网描述 -- Module If you quit from the Python interpreter and enter it again, the definitions y ...

  6. 分组密码_计数器(CTR)模式_原理及java实现

    一.原理: CTR模式是一种通过将逐次累加的计数器进行加密来生成密钥流的流密码,在CTR模式中,每个分组对应一个逐次累加的计数器,并通过对计数器进行加密来生成密钥流.最终的密文分组是通过将计数器加密得 ...

  7. WPF知识点--渐变色(LinearGradientBrush、GradientStop)

    [LinearGradientBrush-- 使用线性渐变绘制区域](https://msdn.microsoft.com/zh-cn/library/system.windows.media.lin ...

  8. CAD参数绘制对齐标注(com接口)

    主要用到函数说明: _DMxDrawX::DrawDimAligned 绘制一个对齐标注.详细说明如下: 参数 说明 DOUBLE dExtLine1PointX 第一条界线开始点X值 DOUBLE ...

  9. JavaScipt30(第二十二个案例)(主要知识点:getBoundingClientRect)

    这是第二十二个案例,这个例子实现的是鼠标移入a标签时,将其高亮. 附上项目链接: https://github.com/wesbos/JavaScript30 以下为注释后的源码: <scrip ...

  10. Oracle数据库自定义函数练习20181031

    --测试函数3 CREATE OR REPLACE FUNCTION FN_TEST3 (NUM IN VARCHAR2) RETURN VARCHAR2 IS TYPE VARCHAR2_ARR ) ...