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. shell学习1---基本的shell命令

    基本脚本 反引号: ``  反引号里面的内容是命令行,通过反引号用户可以将shell命令的输出赋给变量,比如: test=`date +%y%m%d` echo "The time is : ...

  2. async-lock模块理解

    在Appium1.7.1里集成了一个同步模块async-lock用来支持多会话功能. 只能说就算是以单线程高并发闻名的I/O密集型Nodejs也不得不扩展额外的同步块方法,或者说,在现有的计算机体系结 ...

  3. 如何写一个好bug

      自己的总结,和大家分享~

  4. soj1763.传球游戏

    题目不算很难,dp的转移方程也很容易列出: 设dp[i][j] 代表第i次传球之后球回到j手中的传球数.易得: dp[i][j] = dp[i-1][j-1] + dp[i-1][j-1] 再处理一下 ...

  5. 【转】Graphics.DrawImage 方法 IntPtr 结构 GDI 句柄 知识收集

    Graphics.DrawImage 方法 在指定的位置使用原始物理大小绘制指定的 Image. 命名空间:System.Drawing 程序集:System.Drawing(在 system.dra ...

  6. java基础学习:JavaWeb之Cookie和Session

    一.会话概述 1.1.什么是会话? 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话其中不管浏览器发送多少请求,都视为一次会话,直到 ...

  7. Eclipse中如何改变主题

    童鞋们, eclipse主题太丑?想设置护眼的主题? 看看这些主题: 请移驾: Eclipse Color Themes 怎么设设置? 1. 打开”eclipse marketplace“, 如下图: ...

  8. layui结合SpringMVC上传文件以及携带额外的参数上传文件

    今天在使用layui的过程中,遇到了使用其上传文件的模块.自己感觉文件上传还是bootstrapfileinput插件比较好用一些,灵活方便,bootstrapfileinput使用方法参考:http ...

  9. 39 - 同步-异步-IO多路复用

    目录 1 同步与异步 2 阻塞与非阻塞 3 什么是IO 3.1 内核态用户态 3.2 IO两个阶段 3.3 IO模型 3.3.1 同步阻塞IO 3.3.2 同步非阻塞IO 3.3.3 IO多路复用 3 ...

  10. Resouce, platform_device 和 platform_driver 的关系【转】

    转自:http://blog.csdn.net/uruita/article/details/7278313 從2.6版本開始引入了platform這個概念,在開發底層驅動程序時,首先要確認的就是設備 ...