Cod sursa(job #1034102)

Utilizator Teodor94Teodor Plop Teodor94 Data 17 noiembrie 2013 17:40:41
Problema Dtcsu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <cstdio>
#include <tr1/unordered_map>
 
using namespace std;
using namespace std::tr1;
 
#define TOTAL 276997
#define LEN 20
#define ll long long
 
char s[LEN];
ll p2[6];
int exp[6];
unordered_map< ll, bool > h;
 
bool is_digit( char c ) {
    return c >= '0' && c <= '9';
}
 
ll get_int( char A[] ) {
    ll x = 0;
    int i = 0;
    while ( is_digit( A[i] ) ) {
        x = ( ll ) x * 10 + ( A[i] - '0' );
        ++i;
    }
    return x;
}
 
void read() {
    for ( int i = 0; i < TOTAL; ++i ) {
        gets( s );
        ll x = get_int( s );
 
        if ( x & 1 )
            h[x] = true;
    }
}
 
void pregen() {
    p2[0] = 2;
    p2[1] = 4;
    p2[2] = 16;
    p2[3] = 256;
    p2[4] = 65536;
    p2[5] = 1073741824;
    exp[0] = 1;
    exp[1] = 2;
    exp[2] = 4;
    exp[3] = 8;
    exp[4] = 16;
    exp[5] = 30;
}
 
int main() {
    FILE *fout;
    
    freopen( "dtcsu.in", "r", stdin );
    fout = fopen( "dtcsu.out", "w" );
 
    read();
    pregen();
     
    int q, ans = 0;
    scanf( "%d\n", &q );
    while ( q ) {
        gets( s );
        ll x = get_int( s );
         
        if ( x ) {
            if ( !( x & 1 ) ) {
                for ( int i = 5; i >= 0; --i )
                    if ( ( x & ( p2[i] - 1 ) ) == 0 )
                        x >>= exp[i];
            }
            
            unordered_map< ll, bool >::iterator it = h.find( x );
            if ( it != h.end() )
                ++ans;
        }
 
        --q;
    }
     
    fprintf( fout, "%d\n", ans );
    fclose( stdin );
    fclose( fout );
}