/*将所有的点离散开来。避免多重匹配。*/
#include <map>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
bool vis[200];
int s[200];
int cnt[200];
int match[200];
int n;
vector<int> mat[200];
int find(int x)
{
for(int j=0; j<mat[x].size(); j++)
{
int u=mat[x][j];
if(!vis[u])
{
vis[u]=true;
if(match[u]==-1||find(match[u]))
{
match[u]=x;
return true;
}
}
}
return false;
}
int main()
{
map<char,int> v;
v['S']=1;
v['M']=2;
v['L']=3;
v['X']=4;
v['T']=5;
string data[200];
string str;
while(cin >> str)
{
if(str=="ENDOFINPUT") break;
scanf("%d",&n);
memset(match,-1,sizeof(match));
for(int i=1; i<=n; i++)
{
cin >> data[i];
mat[i].clear();
}
int a;
s[0]=0;
for(int i=1; i<=5; i++)
{
scanf("%d",&a);
s[i]=s[i-1]+a;
}
for(int i=1; i<=n; i++)
{
int l=v[data[i][0]];
int r=v[data[i][1]];
for(int j=s[l-1]+1; j<=s[r]; j++)
mat[i].push_back(j);
}
int count=0;
for(int i=1; i<=s[5]; i++)
{
memset(vis,false,sizeof(vis));
if(find(i)) count++;
}
if(count==n) printf("T-shirts rock!\n");
else printf("I'd rather not wear a shirt anyway...\n");
cin >> str;
}
return 0;
}
T-Shirt Gumbo 二分最大匹配 hoj
最新推荐文章于 2016-11-23 22:41:24 发布