(HDOJ-1425 sort )
http://acm.hdu.edu.cn/showproblem.php?pid=1425
题目特点:
数据量大
数据在一定范围
View Code
1 #include<cstring> 2 #include<cstdio> 3 //using namespace std; 4 #define num 1000001 5 int Hash[num]; 6 7 int main( ) 8 { 9 int n; 10 int m; 11 int mid = 500000; 12 int max = -mid; 13 int min = mid; 14 int temp; 15 while( scanf("%d %d",&n,&m) == 2 ) 16 { 17 if( m > n ) 18 m = n; 19 memset(Hash,0,sizeof(Hash)); 20 for( int i=0; i<n; i++ ) 21 { 22 scanf("%d",&temp); 23 if( temp > max ) 24 max = temp; 25 if( temp < min ) 26 min = temp; 27 ++Hash[temp+mid]; 28 } 29 for( i=max+mid,min+=mid; i>=min&&m>0; i-- ) 30 { 31 if( Hash[i] > 0 ) 32 if( --m ) 33 printf("%d ",i-mid); 34 else 35 printf("%d\n",i-mid); 36 } 37 } 38 return 0; 39 }