[HDU

题意:从小到大每三杯第三杯免费,就是每第三杯不要钱,问你要花多少钱。

hint:贪心,就是简单的sort函数运用

#include <iostream>
#include<stdio.h>
#include<algorithm>
#define siz 100005
using namespace std;
int a[siz];
int main()
{
    int T,ans,n,t=1;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1, a+n+1);
        ans = 0;
        for(int i=1;i<=n;i++)
        {
            if(i%3==0) continue;
            ans+=a[i];
        }
        printf("Case #%d: %d
", t++, ans);

    }
    return 0;

}
原文地址:https://www.cnblogs.com/Vikyanite/p/11382543.html