Ural 1025 Democracy in danger

Ural 1025 Democracy in danger

 

有K组,取人数较小的(k+1)/2组即可,每组取(人数+1)/2,排下序就可以了
#include < iostream >
#include
< vector >
#include
< algorithm >
using   namespace  std;
int  main()
{
    
int  k,i,sum = 0 ,temp;
    cin
>> k;   
    vector
< int > vec;
    
for (i = 0 ; i < k; i ++ )
       { cin
>> temp;vec.push_back(temp); }
       
    sort(vec.begin(),vec.end());
    
for (i = 0 ; i <= k / 2 ; i ++ )
      sum
+= (vec[i] + 1 ) / 2 ;
      
    cout
<< sum << endl;  
      
    system(
" pause " );
    
return   0 ;
}

你可能感兴趣的:(Ural 1025 Democracy in danger)