Exemplo n.º 1
0
int main() {
    
    for( cin >> T; T--; ) {
        
        type_cnt = 0;
        type.clear();
        
        cin >> receptacle_cnt;
        for( int i = 0; i < receptacle_cnt; ++i ) {
            cin >> input;
            receptacle[i] = getIndex( input );
        }
        
        cin >> device_cnt;
        for( int i = 0; i < device_cnt; ++i ) {
            cin >> input >> input;
            device[i] = getIndex( input );
        }
        
        cin >> adapter_cnt;
        memset( adapter, 0, sizeof( adapter ) );
        
        for( int i = 0; i < adapter_cnt; ++i ) {
            cin >> input;
            x = getIndex( input );
            cin >> input;
            y = getIndex( input );
            adapter[x][y] = true;
        }

        // 传递闭包 
        for( int i = 0; i < type_cnt; ++i )
            for( int j = 0; j < type_cnt; ++j )
                for( int k = 0; k < type_cnt; ++k )
                    if( adapter[j][i] && adapter[i][k] )
                        adapter[j][k] = true;

        for( int i = 0; i < type_cnt; ++i )
            adapter[i][i] = true;
        
        binmatch.init( device_cnt, receptacle_cnt );
        
        for( int i = 0; i < device_cnt; ++i )
            for( int j = 0; j < receptacle_cnt; ++j )
                if( adapter[device[i]][receptacle[j]] )
                    binmatch.insert( i, j );
                    
        binmatch.run();
        
        cout << device_cnt - binmatch.matchCnt() << endl; 
        
        if( T ) puts( "" ); 

    }
    
}
Exemplo n.º 2
0
int main() {
    
    MP['S'] = 0;
    MP['M'] = 1;
    MP['L'] = 2;
    MP['X'] = 3;
    MP['T'] = 4;
    
    while( cin >> input && input == "START" ) {
        
        cin >> N;
        
        for( int i = 0; i < N; ++i )
            cin >> X[i];
            
        for( int i = 0; i < 5; ++i )
            cin >> S[i];
            
        cin >> input;
            
        binmatch.init( N, S[0] + S[1] + S[2] + S[3] + S[4] );
        
        int pos,    cnt; 
        for( cnt = pos = 0; pos < 5; ++pos ) {
            for( int i = 0; i < S[pos]; ++i, ++cnt ) {
                for( int j = 0; j < N; ++j ) {
                    int x = MP[X[j][0]],    y = MP[X[j][1]];
                    if( x <= pos && y >= pos )
                        binmatch.insert( j, cnt );
                }
            }
        }
        
        binmatch.run();
        
        puts( 
            binmatch.matchCnt() == N ?
            "T-shirts rock!" :
            "I'd rather not wear a shirt anyway..."
        );
        
    }
    
}