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