Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2935 | Accepted: 1376 |
Description
Input
Output
Sample Input
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
Sample Output
T-shirts rock! I'd rather not wear a shirt anyway... I'd rather not wear a shirt anyway...
//二分匹配,把队员看成第一点集,衣服看成第二点集,学生接受衣服的范围和衣服都要预处理一下,之后套匈牙利模板,最大匹配若等于学生数,即能使所有人满意
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N = 510;
int match[N];
bool use[N];
bool s[N][N];
int n, k;
bool dfs(int v)
{
for(int i = 0; i < N; i++)
{
if(s[v][i] == true && use[i] == false)
{
use[i] = true;
if(match[i] == -1 || dfs(match[i]))
{
match[i] = v;
return true;
}
}
}
return false;
}
int hungary()
{
int res = 0;
memset(match, -1, sizeof match);
for(int i = 0; i < n; i++)
{
memset(use, 0, sizeof use);
if(dfs(i)) res++;
}
return res;
}
int ju(char a)
{
if(a == 'S') return 1;
else if(a == 'M') return 2;
else if(a == 'L') return 3;
else if(a == 'X') return 4;
else return 5;
}
int main()
{
char str[20];
char a, b;
int aa[N], bb[N], tmp[10] = {};
while(scanf(" %s", str), strcmp(str, "ENDOFINPUT") != 0)
{
scanf("%d", &n);
memset(s, 0, sizeof s);
for(int i = 0; i < n; i++)
{
scanf(" %c%c", &a, &b);
aa[i] = ju(a); //预处理队员可接受的衣服范围,转换为数字
bb[i] = ju(b);
}
for(int i = 1; i <= 5; i++)
{
scanf("%d", tmp + i);
tmp[i] += tmp[i-1]; //预处理衣服,把每一件衣服独立成一个点
}
scanf(" %s", str);
for(int i = 0; i < n; i++)
{
for(int j = aa[i]; j <= bb[i]; j++)
{
for(int k = tmp[j-1] + 1; k <= tmp[j]; k++)
s[i][k] = true;
}
}
if(hungary() == n) printf("T-shirts rock!\n");
else printf("I'd rather not wear a shirt anyway...\n");
}
return 0;
}