This is an easy problem from uva judge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1860
Adhoc, Complete Search approach.
How I did it
- Read the number of courses and categories.
- Read all the courses and insert into a vector.
- Read all the categories. Save the total courses and minimum required.
- Set a counter in 0.
- If a course if founded inside categories vector. Increment the counter
- If the “set size” is equal to “number of balls +1″ print Y, otherwise print N.
- At the end of the loop if counter is more or equal than minimum print yes, otherwise print no.
Hints
- All the course has 4 digits. Save this as strings. (a course is 0000, 0001, 0003).
Code
#include <iostream> #include <cstdio> #include <vector> using namespace std; int main() { int courses, categories, total, minimum; string str; while(scanf("%d", &courses)) { if(!courses) break; scanf("%d", &categories); vector<string>courseSelected; for(int x=0; x<courses; x++) { cin>>str; courseSelected.push_back(str); } int flag = 1; for(int c=1; c<=categories; c++) { scanf("%d %d", &total, &minimum); int tmp = 0; for(int x=1; x<=total; x++) { cin>>str; for(int y=0; y<courseSelected.size(); y++) { if(courseSelected[y] == str) { tmp++; break; } } } if(tmp<minimum) flag = 0; } if(!flag) printf("no\n"); else printf("yes\n"); } return 0; }