T-Shirt Gumbo
Time Limit: 1000MS | | Memory Limit: 65536K |
Total Submissions: 3141 | | Accepted: 1475 |
Description
Boudreaux and Thibodeaux are student volunteers for this year's ACM South Central Region's programming contest. One of their duties is to distribute the contest T-shirts to arriving teams. The T-shirts had to be ordered in advance using an educated guess as to how many shirts of each size should be needed. Now it falls to Boudreaux and Thibodeaux to determine if they can hand out T-shirts to all the contestants in a way that makes everyone happy.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 4 components:
- Start line - A single line:
START X
where (1 <= X <= 20) is the number of contestants demanding shirts.
- Tolerance line - A single line containing X space-separated pairs of letters indicating the size tolerances of each contestant. Valid size letters are S - small, M - medium, L - large, X - extra large, T - extra extra large. Each letter pair will indicate the range of sizes that will satisfy a particular contestant. The pair will begin with the smallest size the contestant will accept and end with the largest. For example:
MX
would indicate a contestant that would accept a medium, large, or extra large T-shirt. If a contestant is very picky, both letters in the pair may be the same.
- Inventory line - A single line:
S M L X T
indicating the number of each size shirt in Boudreaux and Thibodeaux's inventory. These values will be between 0 and 20 inclusive.
- End line - A single line:
END
After the last data set, there will be a single line:
ENDOFINPUT
Output
For each data set, there will be exactly one line of output. This line will reflect the attitude of the contestants after the T-shirts are distributed. If all the contestants were satisfied, output:
T-shirts rock!
Otherwise, output:
I'd rather not wear a shirt anyway...
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 <cstring>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
const int N = 1050;
char str[N];
struct node
{
int l,r;
}p[N];
int val[N], cnt[N], wight[N][N], match[N], visit[N];
int dfs(int k);
int n;
int main()
{
int a='S', b='M', c='L', d='X', e='T';
cnt[a]=0, cnt[b]=1, cnt[c]=2, cnt[d]=3, cnt[e]=4;
while(scanf("%s",str))
{
if(strcmp(str,"ENDOFINPUT")==0)
{
break;
}
scanf("%d", &n);
for(int i=0;i<n;i++)
{
scanf("%s",str);
a=str[0], b=str[1];
p[i].l=cnt[a], p[i].r=cnt[b];
}
int sum=0;
for(int i=0;i<=4;i++)
{
scanf("%d", &val[i]);
sum+=val[i];
}
scanf("%s",str);
if(sum<n)
{
printf("I'd rather not wear a shirt anyway...\n");
continue;
}
memset(wight,0,sizeof(wight));
memset(match,-1,sizeof(match));
int m=0;
for(int i=0;i<=4;i++)
{
for(int k=1;k<=val[i];k++)
{
for(int j=0;j<n;j++)
{
if(i>=p[j].l&&i<=p[j].r)
{
wight[m][j]=1;
}
}
m++;
}
}
int ans=0;
for(int i=0;i<m;i++)
{
memset(visit,0,sizeof(visit));
if(dfs(i))
{
ans++;
}
}
if(ans==n)
{
printf("T-shirts rock!\n");
}
else
{
printf("I'd rather not wear a shirt anyway...\n");
}
}
return 0;
}
int dfs(int k)
{
for(int i=0;i<n;i++)
{
if(!visit[i]&&wight[k][i])
{
visit[i]=1;
if(match[i]==-1||dfs(match[i]))
{
match[i]=k;
return 1;
}
}
}
return 0;
}
和傻逼一样,只知道模板怎么写,稍微转一点思维就卡死了,,,,,,,,,,,,,,,,
每次有一点小成就就非要得意一下,一点都不知道稳重,,怎么可能每次失败都给你机会去弥补,,,一点都不知道改变