Shopaholic HDU - 1678
考察:贪心
大水题.
思路:
排序,从后往前加.每三个加一个最后的.
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 const int N = 20010; 7 int a[N]; 8 int main() 9 { 10 int T; 11 scanf("%d",&T); 12 while(T--) 13 { 14 int n; 15 scanf("%d",&n); 16 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 17 sort(a+1,a+n+1); 18 int sum = 0; 19 while(n>=3) 20 { 21 sum+=a[n-2]; 22 n-=3; 23 } 24 printf("%d\n",sum); 25 } 26 return 0; 27 }