Cod sursa(job #1730088)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 16 iulie 2016 12:42:50
Problema Bowling Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.1 kb
#include <fstream>
#include <vector>
#include <bitset>

const int DIM = 2e2 + 5;

std::vector <int> SG( DIM );
std::bitset <DIM> Marked;

class input_reader {

private:

    FILE *input_file;
    static const int SIZE = 1 << 12;
    char Buffer[SIZE]; int Cursor;

    inline void Advance( void ) {
        if( ++ Cursor == SIZE ) {
            Cursor = 0;
            fread( Buffer, SIZE, 1, input_file );
        } return;
    }

    inline char Current( void ) {
        return Buffer[Cursor];
    }

public:

    input_reader() {}
    input_reader( const char *file_name ) {
        input_file = fopen( file_name, "r" );
        fread( Buffer, SIZE, 1, input_file );
        Cursor = 0;
    }

    template <class type>
    input_reader &operator >>( type &Value ) {
        Value = 0;

        while( Current() < '0' || Current() > '9' )
            Advance();

        while( Current() >= '0' && Current() <= '9' ) {
            Value = Value * 10 + ( Current() - '0' );
            Advance();
        }

        return *this;
    }

} input_file( "bowling.in" );
std::ofstream output_file( "bowling.out" );

void SolveTestCase( void ) {
    int N, X, Ans = 0, Nr = 0;

    input_file >> N;
    for( int i = 1; i <= N; i ++ ) {
        input_file >> X;

        if( X == 1 )
            Nr ++;

        if( i == N || X == 0 ) {
            Ans = ( Ans ^ ( ( Nr <= 72 ) ? SG[Nr] : SG[ 73 + ( Nr - 73 ) % 12 ] ) );
            Nr = 0;
        }
    }

    output_file << ( ( Ans != 0 ) ? "Nargy" : "Fumeanu" ) << "\n";
    return;
}

int main( int argc, const char *argv[] ) {
    int T; input_file >> T;

    for( int i = 0; i <= 2; i ++ )
        SG[i] = i;

    for( int i = 3; i <= 84; i ++ ) {
        Marked.reset();

        for( int j = 0; j <= i - 1; j ++ ) {
            Marked[ SG[j] ^ SG[i - j - 1] ] = 1;

            if( j <= i - 2 )
                Marked[ SG[j] ^ SG[i - j - 2] ] = 1;
        }

        for( int j = 0; j <= 200; j ++ ) {
            if( Marked[j] == 0 ) {
                SG[i] = j;
                break;
            }
        }
    }

    for( int i = 1; i <= T; i ++ )
        SolveTestCase();

    return 0;
}