• n个点中求任意两点组成斜率的最大值


    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)。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <vector>
     5 #include <cstring>
     6 #include <string>
     7 #include <algorithm>
     8 #include <string>
     9 #include <set>
    10 #include <functional>
    11 #include <numeric>
    12 #include <sstream>
    13 #include <stack>
    14 #include <map>
    15 #include <queue>
    16 #pragma comment(linker, "/STACK:102400000,102400000")
    17 #define CL(arr, val)    memset(arr, val, sizeof(arr))
    18 
    19 #define ll long long
    20 #define inf 0x7f7f7f7f
    21 #define lc l,m,rt<<1
    22 #define rc m + 1,r,rt<<1|1
    23 #define pi acos(-1.0)
    24 
    25 #define L(x)    (x) << 1
    26 #define R(x)    (x) << 1 | 1
    27 #define MID(l, r)   (l + r) >> 1
    28 #define Min(x, y)   (x) < (y) ? (x) : (y)
    29 #define Max(x, y)   (x) < (y) ? (y) : (x)
    30 #define E(x)        (1 << (x))
    31 #define iabs(x)     (x) < 0 ? -(x) : (x)
    32 #define OUT(x)  printf("%I64d
    ", x)
    33 #define lowbit(x)   (x)&(-x)
    34 #define Read()  freopen("a.txt", "r", stdin)
    35 #define Write() freopen("b.txt", "w", stdout);
    36 #define maxn 1010
    37 #define maxv 3000
    38 #define mod 1000000000
    39 using namespace std;
    40 
    41 struct point
    42 {
    43     int x,y,id;
    44     bool operator < (const point a) const
    45     {
    46         return x<a.x;
    47     }
    48 }p[10001];
    49 int main()
    50 {
    51     // freopen("a.txt","r",stdin);
    52     int n,j,k;
    53     scanf("%d",&n);
    54     for(int i=1;i<=n;i++)
    55     {
    56         scanf("%d%d",&p[i].x,&p[i].y);
    57         p[i].id=i;
    58     }
    59     sort(p+1,p+n+1);
    60     double ans=0;
    61     for(int i=2;i<=n;i++)
    62     {
    63         if(p[i].y==p[i-1].y) continue;
    64         if((p[i].y-p[i-1].y)*1.0/(p[i].x-p[i-1].x)>ans)
    65         {
    66             ans=(p[i].y-p[i-1].y)*1.0/(p[i].x-p[i-1].x);
    67             j=p[i].id;
    68             k=p[i-1].id;
    69         }
    70     }
    71     printf("%d %d
    ",k,j);
    72     return 0;
    73 }
  • 相关阅读:
    LUOGU P4113 [HEOI2012]采花
    LUOGU P4251 [SCOI2015]小凸玩矩阵
    bzoj 3230 相似子串——后缀数组
    bzoj 4453 cys就是要拿英魂!——后缀数组+单调栈+set
    洛谷 5061 秘密任务——二分图染色
    bzoj 4104 [Thu Summer Camp 2015]解密运算——思路
    bzoj 4319 cerc2008 Suffix reconstruction——贪心构造
    poj 3415 Common Substrings——后缀数组+单调栈
    CF 504E Misha and LCP on Tree——后缀数组+树链剖分
    bzoj 4278 [ONTAK2015]Tasowanie——后缀数组
  • 原文地址:https://www.cnblogs.com/nowandforever/p/4616937.html
Copyright © 2020-2023  润新知