Cod sursa(job #1732267)

Utilizator antanaAntonia Boca antana Data 21 iulie 2016 12:35:43
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <cstdio>
#include<vector>
#include<ctype.h>
#define MOD1 8191
#define BUF_SIZE 4096
#define MAXN 276997

using namespace std;
vector<long long>v[MOD1];

int pos=BUF_SIZE;
char buf[BUF_SIZE];

inline char getChar(FILE *f)
{
    if(pos==BUF_SIZE)
    {
        fread(buf, 1, BUF_SIZE, f);
        pos=0;
    }
    return buf[pos++];
}
inline long long getNumber(FILE *f)
{
    long long nr=0;
    char c;
    c=getChar(f);
    while(!isdigit(c))
        c=getChar(f);
    while(isdigit(c))
        nr=nr*10+c-'0', c=getChar(f);
    return nr;
}

inline void adauga(int key1, long long key2)
{
    v[key1].push_back(key2);
}
inline int check(long long x)
{
    int key1=(x&MOD1), sz;

    sz=v[key1].size();
    for(int i=0;i<sz;++i)
        if(v[key1][i] == x)
            return 1;
    return 0;
}
int main()
{
    FILE *fin, *fout;
    fin=fopen("dtcsu.in", "r");
    fout=fopen("dtcsu.out", "w");
    long long x, q, nr=0;
    for(int i=1;i<=MAXN;++i)
    {
        x=getNumber(fin);
        if((x&1)) adauga((x&MOD1), x);
    }

    q=getNumber(fin);
    for(int i=1;i<=q;++i)
    {
        x=getNumber(fin);
        while(!(x&1))
            x=(x>>1);
        nr+=check(x);
    }

    fprintf(fout, "%lld", nr);

    fclose(fin);
    fclose(fout);
    return 0;
}