问题:主要是要能看懂题意...题很简单... 顺便感谢下群里大佬的翻译
每顿饭有M种食物,输入的前N种食物代表着可能包含的食物有哪些
然后输入一个k,剩下有k+1个部分
每部分代表着第i个学生吃了含有这些食物的饭就会中毒
最后一行那个数是M
第一个学生吃了之后没问题,求其他学生吃过后会不会中毒
然后输入一个k,剩下有k+1个部分
每部分代表着第i个学生吃了含有这些食物的饭就会中毒
最后一行那个数是M
第一个学生吃了之后没问题,求其他学生吃过后会不会中毒
分析:其实只需要拿每个人的危险食物和第一个人的危险物品做对比就行...就这一点
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?
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).
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.
7 Rafinad Kefir Pastila Smetana Chokolade Kljukva Imbir 3 3 Rafinad Kefir Imbir 1 Rafinad 3 Kefir Kljukva Smetana 2 Imbir Smetana 3
output
YES NO MAYBE
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main(){
vector<string> all_s;
vector<string> no_danger;
int all_num,no_dangernum,k,m;
string temp;
scanf("%d",&all_num);
for(int i=0;i<all_num;i++){
cin>>temp;
all_s.insert(all_s.end(),temp); //总的食物列表
}
scanf("%d",&k);
scanf("%d",&no_dangernum);
for(int ii=0;ii<no_dangernum;ii++){
cin>>temp;
no_danger.insert(no_danger.end(),temp); //好的食物(没添加的食物)
}
int n[105],n1[105],doubtnum=all_num-no_dangernum;
for(int i=0;i<k;i++){
scanf("%d",&n[i]);
n1[i]=n[i];
for(int j=0;j<n[i];j++){
string t;
cin>>t;
vector<string>::iterator iter=std::find(no_danger.begin(),no_danger.end(),t);
if(iter!=no_danger.end())
n1[i]--;
}
}
scanf("%d",&m);
for(int i=0;i<k;i++){
if(n1[i]==0){
printf("YES\n");
continue;
}
else if(n1[i]<=doubtnum-m) printf("MAYBE\n");
else printf("NO\n");
}
return 0;
}