码迷,mamicode.com
首页 > 其他好文 > 详细

51Nod - 1100 斜率最大

时间:2017-08-14 14:25:41      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:scanf   log   struct   names   its   blog   turn   pos   scan   

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=10005;
struct point
{
    double x;
    double y;
    int ipos;
};//斜率最大的两个点,一定相邻
double iMatr=-100;
bool cmp(point a,point b)
{
    return a.x<b.x;
}
double getMatr(point a,point b)
{
    return 1.0*(b.y-a.y)/(b.x-a.x);
}
int main()
{
    point p[maxn];
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
       scanf("%lf%lf",&p[i].x,&p[i].y);
       p[i].ipos=i;
    }
    sort(p+1,p+1+n,cmp);//排序
    point Ta,Tb;
    for(int i=1;i<=n-1;i++)
    {
        if(getMatr(p[i],p[i+1])>iMatr)
        {
            iMatr=getMatr(p[i],p[i+1]);
                Ta=p[i];
                Tb=p[i+1];
        }
    }
    printf("%d %d\n",Ta.ipos,Tb.ipos);
}

  

51Nod - 1100 斜率最大

标签:scanf   log   struct   names   its   blog   turn   pos   scan   

原文地址:http://www.cnblogs.com/masterchd/p/7357218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!