Skip to content

Commit 018b30a

Browse files
committed
Create 336C - Vasily the Bear and Sequence.cpp
1 parent ea77d19 commit 018b30a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//4331596 Aug 24, 2013 12:22:08 PM fuwutu 336C - Vasily the Bear and Sequence GNU C++0x Accepted 124 ms 400 KB
2+
#include <cstdio>
3+
4+
int main()
5+
{
6+
int n, a[100000], count[32] = {0};
7+
bool b[32][32] = {false};
8+
scanf("%d", &n);
9+
for (int i = 0; i < n; ++i)
10+
{
11+
scanf("%d", &a[i]);
12+
int x = a[i], index = 0, zero[32], zerocount = 0;
13+
while (x != 0)
14+
{
15+
if (x % 2 == 1)
16+
{
17+
count[index] += 1;
18+
for (int j = 0; j < zerocount; ++j)
19+
{
20+
b[index][zero[j]] = true;
21+
}
22+
}
23+
else
24+
{
25+
zero[zerocount++] = index;
26+
}
27+
x /= 2;
28+
index += 1;
29+
}
30+
}
31+
32+
int v = 31;
33+
for (;;)
34+
{
35+
int j = 0;
36+
for (; j < v; ++j)
37+
{
38+
if (!b[v][j])
39+
{
40+
break;
41+
}
42+
}
43+
if (j == v)
44+
{
45+
break;
46+
}
47+
--v;
48+
}
49+
int k = count[v];
50+
printf("%d\n", k);
51+
52+
int pv = 1 << v;
53+
for (int i = 0; i < n; ++i)
54+
{
55+
if ((a[i] & pv) != 0)
56+
{
57+
printf((--k != 0 ? "%d " : "%d\n"), a[i]);
58+
}
59+
}
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)