Birthday Cake Kattis - birthdaycake (几何)
题目链接:
https://cn.vjudge.net/problem/Kattis-birthdaycake
题目大意:
自己翻译
具体思路:
判断每个蜡烛之间都至少被一条线分隔开(在线的两侧),然后判断块数==蜡烛个数。
判断块数的时候,假设一开始这些m线都是平行的,那么当前有m+1块,每次多一个交点就是多一个块。
AC代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define inf 0x3f3f3f3f 5 #define LL_inf (1ll << 60) 6 const int maxn = 1e5 + 100; 7 const int mod = 1e9 + 7; 8 const double eps = 1e-5; 9 pair< int, int >sto[maxn]; 10 struct node 11 { 12 int a,b,c; 13 } q[maxn]; 14 int n,m,r; 15 bool judge(int t1,int t2) 16 { 17 for(int i=1 ; i<=m ; i++ ) 18 { 19 int s1=q[i].a*sto[t1].first+q[i].b*sto[t1].second + q[i].c; 20 int s2=q[i].a*sto[t2].first+q[i].b*sto[t2].second + q[i].c; 21 if(s1*s2<0) 22 return true; 23 } 24 return false; 25 } 26 set<pair<double,double >>vis; 27 int main() 28 { 29 30 scanf("%d %d %d",&n,&m,&r); 31 for(int i = 1; i <= n ; i++ ) 32 { 33 scanf("%d %d",&sto[i].first,&sto[i].second); 34 } 35 for(int i = 1 ; i <= m ; i++) 36 { 37 scanf("%d %d %d",&q[i].a,&q[i].b,&q[i].c); 38 } 39 int flag=1; 40 for(int i = 1 ; i <= n ; i++) 41 { 42 for(int j=1 ; j<=n ; j++) 43 { 44 if(i==j) 45 continue; 46 if(!judge(i,j)) 47 { 48 printf("no\n"); 49 return 0; 50 } 51 } 52 } 53 for(int i=1; i<=m; i++) 54 { 55 for(int j=1; j<=m; j++) 56 { 57 if(i==j)continue; 58 if(q[i].a*q[j].b==q[i].b*q[j].a)continue; 59 double t1=(q[i].c*q[j].b-q[j].c*q[i].b)*1.0/((q[j].a*q[i].b-q[i].a*q[j].b)*1.0); 60 double t2=(q[i].a*q[j].c-q[i].c*q[j].a)*1.0/(q[j].a*q[i].b-q[i].a*q[j].b); 61 if(t1*t1+t2*t2<r*r)vis.insert(make_pair(t1,t2)); 62 } 63 } 64 if(vis.size()+m+1==n){ 65 printf("yes\n"); 66 } 67 else printf("no\n"); 68 return 0; 69 }