Loading

[HDU - 5999]The Third Cup is Free

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

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\n", t++, ans);

    }
    return 0;

}

 

posted @ 2019-08-20 14:05  ViKyanite  阅读(204)  评论(0)    收藏  举报