UVALive 6263 The Dragon and the knights --統計,直線分平面

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   art   

題意:給n條直線,將一個平面分成很多個部分,再給m個騎士的座標,在一個部分內只要有一個騎士即可保護該部分,問給出的m個騎士是不是保護了所有部分。

解法:計算每個騎士與每條直線的位置關係(上面還是下面),用0,1表示,所以每個騎士會有一個01串,最後統計出這n條直線分成的部分數(可能有平行的),然後排序每個騎士的01串,看有多少個處在不同部分的騎士(01串不同的個數),然後比較個數關係,得出答案。

代碼:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <string>#define ll long longusing namespace std;#define N 50007struct Line{    int A,B,C;}line[107];bool UPLine(Line ka,ll x,ll y){    ll res = ka.A*x + ka.B*y + ka.C;    return res > 0;}bool intersection(Line ka,Line kb){    if(ka.A*kb.B == ka.B*kb.A)        return false;    return true;}string ss[N];int main(){    int t,n,m,i,j;    int x,y;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        for(i=0;i<n;i++)            scanf("%d%d%d",&line[i].A,&line[i].B,&line[i].C);        string tmp = "";        for(i=0;i<n;i++)            tmp += "0";        for(i=0;i<m;i++)        {            scanf("%d%d",&x,&y);            ss[i] = tmp;            for(j=0;j<n;j++)            {                if(UPLine(line[j],x,y))                    ss[i][j] = ‘1‘;            }        }        int C = n+1;        for(i=0;i<n;i++)        {            for(j=i+1;j<n;j++)                if(intersection(line[i],line[j]))                    C++;        }        sort(ss,ss+m);        int cnt = 1;        for(i=1;i<m;i++)        {            if(ss[i] != ss[i-1])                cnt++;        }        if(cnt >= C)            puts("PROTECTED");        else            puts("VULNERABLE");    }    return 0;}
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.