http://ac.jobdu.com/problem.php?id=1402
位运算没的说,不过,如果每道题都考STL,那还有意思么?
1 #include <stdio.h>
2 #include <bitset>
3 using namespace std;
4
5 bitset<1000001> bits;
6 bitset<1000001> bits_assit;
7 int main()
8 {
9 int n;
10 while(scanf("%d",&n)!=EOF){
11 bits.reset();
12 bits_assit.reset();
13 int i;
14 int temp;
15 int count=0;
16 for(i=0;i<n;i++){
17 scanf("%d",&temp);
18 if(!bits_assit[temp]){//如果第一次出现
19 bits.set(temp);
20 bits_assit.set(temp);
21 count++;
22 }else if(bits_assit[temp]){//如果已经出现过
23 if(bits[temp]){
24 bits.reset(temp);
25 count--;
26 }
27 }
28 }
29 bool first_time=true;
30 printf("%d\n",count);
31 if(!count){
32 continue;
33 }
34 for(i=1;i<=1000000;i++){
35 if(bits[i]){
36 if(first_time){
37 first_time=false;
38 }else{
39 putchar(' ');
40 }
41 printf("%d",i);
42 }
43 }
44 putchar('\n');
45 }
46 }
47