51nod 1100:斜率最大
生活随笔
收集整理的這篇文章主要介紹了
51nod 1100:斜率最大
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接
斜率最大點(diǎn)對(duì)橫坐標(biāo)必相鄰
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 100;struct point {int x, y, pos;bool operator < (const point& rhs)const{return x<rhs.x;} } a[maxn]; double xielv(point a, point b) {return (a.y-b.y)*1.0/(a.x-b.x); }int main() {int n, x, y;scanf("%d", &n);for(int i=0; i<n; i++){scanf("%d%d", &x, &y);a[i] = (point){x, y, i+1};}sort(a, a+n);double maxxl = -1e9;int index = -1;for(int i=1; i<n; i++){if(maxxl < xielv(a[i], a[i-1])){maxxl = xielv(a[i], a[i-1]);index = i;}}if(a[index].x < a[index-1].x) printf("%d %d\n", a[index].pos, a[index-1].pos);else printf("%d %d\n", a[index-1].pos, a[index].pos); }?
轉(zhuǎn)載于:https://www.cnblogs.com/Just--Do--It/p/6415457.html
總結(jié)
以上是生活随笔為你收集整理的51nod 1100:斜率最大的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java--xml文件读取(SAX)
- 下一篇: 服务概述