#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 88404
using namespace std;
struct Node
{
int v,next;
}edge[N];
int head[N], m, pre[N];
bool mark[N];
void add_edge( int u, int v, int &num )
{
edge[num].v = v;
edge[num].next = head[u];
head[u] = num ++;
}
int get_id( char c )
{
if( c == 'S' ) return 1;
else if( c == 'M' ) return 2;
else if( c == 'L' ) return 3;
else if( c == 'X' ) return 4;
else return 5;
}
void get_map( int n )
{
char ch[4];
int p[25][2];
memset(head,-1,sizeof(head));
for( int i = 1; i <= n; i ++ )
{
scanf("%s",ch);
p[i][0] = get_id(ch[0]);
p[i][1] = get_id(ch[1]);
}
int nv = n,num = 0;
for( int i = 1; i <= 5; i ++ )
{
scanf("%d",&m);
for( int j = nv+1; j <= m+nv; j++ )
for( int k = 1; k <= n; k ++ )
if( p[k][0]<=i&&p[k][1]>=i )
add_edge(k,j,num);
nv+=m;
}
m = nv;
}
bool dfs( int u )
{
for( int p=head[u]; p!=-1; p=edge[p].next )
if( !mark[ edge[p].v ])
{
mark[ edge[p].v ] = true;
if( pre[edge[p].v]==-1 || dfs( pre[edge[p].v] ) )
{
pre[ edge[p].v ] = u;
return true;
}
}
return false;
}
bool hungry( int n )
{
int ans = 0;
for( int i=1; i <= m; i ++ ) pre[i] = -1;
for( int i = 1; i <= m; i ++ )
{
for( int j=1; j<=m; j++ ) mark[j] = false;
if( dfs(i) ) ans++;
}
if( ans==n ) return true;
else return false;
}
int main()
{
int n;
char s[30];
while( scanf("%s",s)!=EOF )
{
if( strcmp(s, "ENDOFINPUT") == 0 ) break;
scanf("%d",&n);
get_map(n);
scanf("%s",s);
if( hungry(n) ) printf("T-shirts rock!\n");
else printf("I'd rather not wear a shirt anyway...\n");
}
return 0;
}
poj 2584
最新推荐文章于 2019-01-08 01:52:54 发布