Uvalive 6263 the dragon and the knights-statistics, straight line split

Source: Internet
Author: User

Question: give n straight lines, divide a plane into multiple parts, and then give m the coordinates of the server guard. In one part, only one server guard can protect this part, ask if the M server guard provided protects all parts.

Solution: Calculate the positional relationship between each server guard and each line (above or below), expressed in, so each server guard has a 01 string, finally, the number of parts divided into the n straight lines (which may be parallel) is calculated, and the 01 strings of each server are sorted, check the number of servers in different parts (01 strings with different numbers), and then compare the number relationship to get the answer.

Code:

#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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.