poj 2584

9 篇文章 0 订阅
5 篇文章 0 订阅
#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值