标签:
START 1 ST 0 0 1 0 0 END START 2 SS TT 0 0 1 0 0 END START 4 SM ML LX XT 0 1 1 1 0 END ENDOFINPUT
T-shirts rock! I‘d rather not wear a shirt anyway... I‘d rather not wear a shirt anyway...
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector> 5 using namespace std; 6 const int maxn = 30; 7 int bound[maxn],shirt[maxn],n; 8 vector<int>Link[maxn]; 9 bool e[maxn][maxn],used[maxn]; 10 bool match(int u){ 11 for(int i = 1; i <= 5; ++i){ 12 if(e[u][i] && !used[i]){ 13 used[i] = true; 14 if(Link[i].size() < bound[i]){ 15 Link[i].push_back(u); 16 return true; 17 } 18 for(int j = Link[i].size()-1; j >= 0; --j){ 19 if(match(Link[i][j])){ 20 Link[i][j] = u; 21 return true; 22 } 23 } 24 } 25 } 26 return false; 27 } 28 char ans[2][50] = {"I‘d rather not wear a shirt anyway...\n","T-shirts rock!\n"}; 29 int main(){ 30 char str[20]; 31 shirt[‘S‘-‘A‘] = 1; 32 shirt[‘M‘-‘A‘] = 2; 33 shirt[‘L‘-‘A‘] = 3; 34 shirt[‘X‘-‘A‘] = 4; 35 shirt[‘T‘-‘A‘] = 5; 36 while((~scanf("%s",str)) && strcmp(str,"ENDOFINPUT")){ 37 scanf("%d",&n); 38 memset(e,false,sizeof e); 39 for(int i = 1; i <= n; ++i){ 40 scanf("%s",str); 41 for(int j = shirt[str[0]-‘A‘]; j <= shirt[str[1]-‘A‘]; ++j) 42 e[i][j] = true; 43 } 44 for(int i = 1; i <= 5; ++i) 45 scanf("%d",bound + i); 46 scanf("%s",str); 47 for(int i = 0; i < maxn; ++i) Link[i].clear(); 48 int ret = 0; 49 for(int i = 1; i <= n; ++i){ 50 memset(used,false,sizeof used); 51 if(match(i)) ++ret; 52 } 53 printf("%s",ans[ret == n]); 54 } 55 return 0; 56 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4854185.html