1350. Canteen
1350. Canteen
Time limit: 1.0 second Memory limit: 64 MB It’s dangerous to eat in a canteen — you may be poisoned by a not fresh food. One may fall into a coma because of the canteen’s chicken and the other feels OK. And vice versa. The food is cooked from M different food stuffs. There are N different food stuffs in the menu but not all of them are at the distribution. Assume that K + 1 students eat the food and we know for each student what products may poison him. The first student eats and he is not poisoned. How the dinner affect on the other students?Input
The first line contains an integer N (1 ≤ N ≤ 100). The next N lines contain the food stuffs names — non-empty sequences of Latin letters and digits with length not more than 40 symbols. Then there is a number K (1 ≤ K ≤ 100) and K + 1 blocks describing the menu food stuffs dangerous for the canteen visitors afterwards. The i th block starts with a line with an integer Ni — an amount of dangerous food stuffs and then there are Ni lines with the names of those dangerous stuffs (0 ≤ Ni ≤ N). The first block describes the food stuffs dangerous for the first student, the next K blocks — for the rest ones. The input ends with the line containing an integer M (0 ≤ M ≤ N).Output
K lines — the i th line should contain:- YES, if the dinner is harmless for the (i + 1)st student,
- NO, if among the food stuffs there is a dangerous one for the (i + 1)st student,
- MAYBE, if there may be different situations under the given conditions.
Sample
| input | output |
|---|---|
7 Rafinad Kefir Pastila Smetana Chokolade Kljukva Imbir 3 3 Rafinad Kefir Imbir 1 Rafinad 3 Kefir Kljukva Smetana 2 Imbir Smetana 3 | YES NO MAYBE |
不愧为大水题,一次AC,(用字典树) ***********************************************************************************************
1 #includeView Code2 #include<string> 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 int n,k,i,j; 9 char str[1000][105]; 10 char c[1000]; 11 int stu[1000]; 12 int food[1000]; 13 int stufod[1000][1000]; 14 struct tree 15 { 16 int ve; 17 struct tree *p[131]; 18 tree() 19 { 20 int i; 21 ve=-1; 22 for(i=0;i<131;i++) 23 p[i]=NULL; 24 } 25 }; 26 int ans; 27 tree *root; 28 int insert(char *s) 29 { 30 int len=strlen(s); 31 tree *r=root; 32 for(int ig=0;ig ) 33 { 34 if(r->p[s[ig]]==NULL) 35 r->p[s[ig]]=new tree(); 36 r=r->p[s[ig]]; 37 } 38 if(r->ve==-1) 39 { 40 r->ve=ans; 41 ans++; 42 } 43 return r->ve; 44 } 45 int b; 46 int ms; 47 int sum=0; 48 int main() 49 { 50 cin>>n; 51 root=new tree(); 52 getchar(); 53 ans=1; 54 for(i=0;i ) 55 scanf("%s",str[i]); 56 cin>>k; 57 cin>>b; 58 for(j=0;j) 59 { 60 scanf("%s",c); 61 food[insert(c)]=1; 62 } 63 for(i=0;i ) 64 { 65 if(food[insert(str[i])]==0) 66 { 67 food[insert(str[i])]=0; 68 sum++; 69 } 70 } 71 for(i=1;i<=k;i++) 72 { 73 cin>>stu[i]; 74 for(j=1;j<=stu[i];j++) 75 { 76 scanf("%s",c); 77 stufod[i][j]=insert(c); 78 } 79 80 } 81 cin>>ms; 82 for(i=1;i<=k;i++) 83 { 84 int gs=1; 85 int suma=0; 86 for(j=1;j<=stu[i];j++) 87 { 88 if(food[stufod[i][j]]==0) 89 suma++; 90 } 91 if(suma>0) 92 { 93 if(sum-suma<ms) 94 cout<<"NO"<<endl; 95 else 96 cout<<"MAYBE"<<endl; 97 } 98 else 99 cout<<"YES"<<endl; 100 } 101 return 0; 102 103 }
转载于:https://www.cnblogs.com/sdau--codeants/p/3246352.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
