Cod sursa(job #396866)

Utilizator ssergiussSergiu-Ioan Ungur ssergiuss Data 15 februarie 2010 23:34:28
Problema Taramul Nicaieri Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <algorithm>
using namespace std;

#define DIM 1<<7

int N, K, X[ DIM ], Y[ DIM ];
int muchie[ DIM ][ DIM ];

int main() {

    freopen( "harta.in", "r", stdin );
    freopen( "harta.out", "w", stdout );

    int i, j;

    scanf( "%d", &N );
    for( i = 1; i <= N; ++i )
        scanf( "%d %d", &X[ i ], &Y[ i ] );

    for( i = 1; i <= N; ++i ) {

        for( j = 1; j <= N; ++j )
            if( j != i && X[ i ] )
                if( Y[ j ] && !muchie[ j ][ i ] ) {

                    ++K;
                    muchie[ i ][ j ] = 1;
                    --X[ i ];
                    --Y[ j ];
                }
        for( j = 1; j <= N; ++j )
            if( j != i && X[ i ] )
                if( Y[ j ] ) {

                    ++K;
                    muchie[ i ][ j ] = 1;
                    --X[ i ];
                    --Y[ j ];
                }
    }

    printf( "%d\n", K );
    for( i = 1; i <= N; ++i )
        for( j = 1; j <= N; ++j )
            if( muchie[ i ][ j ] )
                printf( "%d %d\n", i, j );

    return 0;
}