BZOJ1007|水平可見直線|類比

來源:互聯網
上載者:User

標籤:

Description
在xoy直角座標平面上有n條直線L1,L2,...Ln,若在y值為正無窮大處往下看,能見到Li的某個子線段,則稱Li為可見的,否則Li為被覆蓋的.
例如,對於直線:L1:y=x; L2:y=-x; L3:y=0
則L1和L2是可見的,L3是被覆蓋的.
給出n條直線,表示成y=Ax+B的形式(|A|,|B|<=500000),且n條直線兩兩不重合.求出所有可見的直線.
Input
第一行為N(0 < N < 50000),接下來的N行輸入Ai,Bi
Output
從小到大輸出可見直線的編號,兩兩中間用空格隔開,最後一個數字後面也必須有個空格
Sample Input
3
-1 0
1 0
0 0
Sample Output
1 2

解析:類比水題,但我一開始沒過是因為類型不對……

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{    double a,b;    int num;}l[50001],s[50001];int tot=0,top=0;bool cmp(node a,node b){    if (a.a!=b.a) return a.a<b.a;    return a.b>b.b;} bool cmp2(node a,node b) { return a.num<b.num;  }inline void insert(node x){    if (s[top].a==x.a) return;    if (top<2) { s[++top]=x; return; }     while (1)    {        if (top==1) { s[++top]=x; return; }         double x1=(s[top].b-x.b)/(x.a-s[top].a);        double x2=(s[top].b-s[top-1].b)/(s[top-1].a-s[top].a);        if (x1<=x2 || (x1-x2)<0.00001) top--;            else { s[++top]=x; return;    }    }    return;}int main(){    int n;    scanf("%d",&n);    if (n==1) cout << 1 << endl;    for (int i=1; i<=n; i++) { tot++; scanf("%lf%lf",&l[tot].a,&l[tot].b); l[tot].num=i; }    if (n==2)        if (l[1].a==l[2].a) { if (l[1].b>l[2].b) cout << 1; else cout << 2;  }            else cout << 1 << " " << 2;    sort(l+1,l+n+1,cmp);    for (int i=1; i<=n; i++) insert(l[i]);    sort(s+1,s+top+1,cmp2);    for (int i=1; i<=top; i++) cout << s[i].num << " ";    return 0;    } 

 

BZOJ1007|水平可見直線|類比

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.