The Third Cup is Free

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1811    Accepted Submission(s): 846


Problem Description
Panda and his friends were hiking in the forest. They came across a coffee bar inside a giant tree trunk.

Panda decided to treat everyone a cup of coffee and have some rest. Mr. Buck, the bartender greeted Panda and his animal friends with his antler. He proudly told them that his coffee is the best in the forest and this bar is a Michelin-starred bar, thats why
the bar is called Starred Bucks.

There was a campaign running at the coffee bar: for every 3 cups of coffee, the cheapest one is FREE. After asking all his friends for their flavors, Panda wondered how much he need to pay.
 

Input
The first line of the input gives the number of test cases, T.

T test cases follow. Each test case consists of two lines. The first line contains one integer N, the number of cups to be bought.

The second line contains N integers
p1,p2,⋅⋅⋅,pN
representing the prices of each cup of coffee.
 

Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the least amount of money Panda need to pay.

limits


1 ≤ T ≤ 100.

1 ≤ N ≤ 105.

1 ≤ pi ≤ 1000.

 


Sample Input

2
3
1 2 3
5
10 20 30 20 20
 

Sample Output

Case #1: 5
Case #2: 80

题意:三杯中价格最低的一杯免费。

思路:直接按价格从大到小排序,三个一循环。

#include<stdio.h>
#include<algorithm>
using namespace std; bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int T, N;
int pi[100005];
scanf("%d", &T);
int n = 0;
while (T--)
{
n++;
int sum = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++)
{
scanf("%d", &pi[i]);
}
sort(pi, pi + N,cmp);
for (int i = 0; i < N; i++)
{
if ((i + 1) % 3 != 0)
{
sum+=pi[i];
}
}
printf("Case #%d: %d\n", n, sum);
}
return 0;
}

HDU - 5999 The Third Cup is Free 贪心 简单题的更多相关文章

  1. cf 605A Sorting Railway Cars 贪心 简单题

    其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i], ...

  2. CF 500 C. New Year Book Reading 贪心 简单题

    New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...

  3. POJ 2393 贪心 简单题

    有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生 ...

  4. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  5. HDU - 2199 Can you solve this equation? 二分 简单题

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. POJ 2260 Error Correction 模拟 贪心 简单题

    Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6825   Accepted: 4289 ...

  7. hdu2187悼念512汶川大地震遇难同胞——老人是真饿了(贪心 简单题)

    传送门 简单题 #include<bits/stdc++.h> using namespace std; struct node { double dan,weight; }a[]; bo ...

  8. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  9. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

随机推荐

  1. Java并发编程原理与实战二十一:线程通信wait&notify&join

    wait和notify wait和notify可以实现线程之间的通信,当一个线程执行不满足条件时可以调用wait方法将线程置为等待状态,当另一个线程执行到等待线程可以执行的条件时,调用notify可以 ...

  2. anonymous namespace V.S. static variant

    [anonymous namespace V.S. static variant] 在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做为函数名或者全局变量名,则在链 ...

  3. <转>Android APP字体大小,不随系统的字体大小变化而变化的方法

    从android4.0起系统设置的”显示“提供设置字体大小的选项.这个设置直接会影响到所有sp为单位的字体适配,所以很多app在设置了系统字体后瞬间变得面目全非.下面是解决方案 Resources r ...

  4. CodeForces - 1040B Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  5. 【leetcode 简单】 第九十一题 找不同

    给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...

  6. C++ Primer 5th 第17章 标准库特殊设施

    C++新标准库提供了很多新功能,它们更加强大和易用. tuple类型 tuple是一种类似pair的模板,pair可以用来保存一对逻辑上有关联的元素对.但与pair不同的是,pair只能存储两个成员, ...

  7. Spring4笔记5--基于注解的DI(依赖注入)

    基于注解的DI(依赖注入): 对于 DI 使用注解,将不再需要在 Spring 配置文件中声明 Bean 实例.只需要在 Spring 配置文件中配置组件扫描器,用于在指定的基本包中扫描注解. < ...

  8. Intent 对象在 Android 开发中的应用

    转自(http://www.ibm.com/developerworks/cn/opensource/os-cn-android-intent/) Android 是一个开放性移动开发平台,运行在该平 ...

  9. javascript按照指定格式获取上一个月的日期

    //get pre month//get pre month function getPreMonth() { var date=new Date().Format("yyyy-MM-dd& ...

  10. 【写在NOIP前】

    快NOIP了,感觉自己得总结一下吧. 1.要自信啊,相信自己啊,我明明还是有些实力的是吧. 哪怕之前被教练怎么怼,自己别放弃啊 一定要注意心态吧,考试的时候怎么都不能慌,你不会的题也不会有多少人会做的 ...