Created
November 10, 2010 12:04
-
-
Save shihongzhi/670763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define BITNUMBER 32 | |
#define N 10000000 | |
#define random(x) rand()%x | |
int a[N/BITNUMBER+1]; | |
void set(int i) | |
{ | |
a[i/BITNUMBER]|=1<<(i%BITNUMBER); | |
} | |
void clean(int i) | |
{ | |
a[i/BITNUMBER]&=~1<<(i%BITNUMBER); | |
} | |
int test(int i) | |
{ | |
return (a[i/BITNUMBER]>>(i%BITNUMBER))&1; | |
} | |
int main() | |
{ | |
int i,temp; | |
for(i=0;i<10000000;i++) | |
clean(i); | |
i=0; | |
while(i<1000000) //1000000个不重复的随机数 | |
{ | |
temp=random(10000000); | |
if(!test(temp)){ | |
i++; | |
set(temp); | |
} | |
} | |
for(i=0;i<10000000;i++) | |
if(test(i)) | |
printf("%d\n",i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment