Cod sursa(job #1033845)

Utilizator GheorgheMihaiMihai Gheorghe GheorgheMihai Data 17 noiembrie 2013 15:48:39
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <stdio.h>
#include <assert.h>

#include <algorithm>

using namespace std;

int n;

long long v[50002];

int cautare (long long x)
{
	int st = 1, dr = v[0], m, sol=1;
	while (st <= dr)
	{
		m = (st + dr) >> 1;
		if (v[m] >= x)
		{
			sol = m;
			dr = m - 1;
		}
		else
			st = m + 1;
	}
	return v[sol] == x;
}

int main ()
{
	freopen ("dtcsu.in", "r", stdin);
	freopen ("dtcsu.out", "w", stdout);
	
	long long x = 0;
	int i, j, sol = 0;
	char s[22];
	int cate = 276997;
	for (i = 1; i <= cate; i ++)
	{
		gets (s + 1);
		x = 0;
		for (j = 1; '0' <= s[j] && s[j] <= '9'; j ++)
			x = x * 10 + s[j] - '0';
		if ((x & 1) == 0)
			continue;
		else
			v[++v[0]] = x;
	}
	sort (v + 1, v + v[0] + 1);
	scanf ("%d\n", &n);
	while (n --)
	{
		gets (s + 1);
		x = 0;
		for (j = 1; '0' <= s[j] && s[j] <= '9'; j ++)
			x = x * 10 + s[j] - '0';
		if ((x & 1) == 0)
			x /= x & -x;
		if (cautare(x))
			sol ++;
	}
	printf ("%d\n", sol);
	return 0;
}