UVa 10474 Where is the Marble?

UVa 10474 Where is the Marble?
我认为刘汝佳在《算法竞赛入门经典》一书中的题目分类有错~这题怎么被归为暴力求解了呢?
题目大意:给出n个正整数,每个数都小于等于10000;有m次提问,问题是x在这个序列中第几大,如果x不在序列中,输出不在序列中。
以下是我的代码:
#include < stdio.h >
#include
< string .h >
int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    
const   long  maxn = 10008 ;
    
long  n,m,test = 0 ,be[maxn],pos[maxn];
    
while (scanf( " %ld%ld " , & n, & m) == 2 )
    {
       
if (n == 0 || m == 0 break ;
       test
++ ;
       printf(
" CASE# %ld:\n " ,test);
       memset(be,
0 , sizeof (be));
       memset(pos,
0 , sizeof (pos));
       
for ( long  i = 1 ;i <= n;i ++ )
       {
          
long  t;
          scanf(
" %ld " , & t);
          be[t]
++ ;
       }
       
//   Read In
        long  tmp = 0 ;
       
for ( long  i = 0 ;i < maxn;i ++ )
         
if (be[i])
         {
            pos[i]
= tmp + 1 ;
            tmp
+= be[i];
         }
       
//   Init
        for ( long  i = 1 ;i <= m;i ++ )
       {
          
long  t;
          scanf(
" %ld " , & t);
          
if (pos[t])
            printf(
" %ld found at %ld\n " ,t,pos[t]);
          
else  printf( " %ld not found\n " ,t);
       }
    }
return   0 ;
}


你可能感兴趣的:(UVa 10474 Where is the Marble?)