The Third Cup is Free
来源:互联网 发布:网络推广员面试题 编辑:程序博客网 时间:2024/05/18 01:19
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,・・・,pNp1,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 ≤ 105105.
∙∙ 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<iostream>#include<cstdio>#include<algorithm>using namespace std;bool ac(int a,int b){ return a>b;}int main(){ int T,N,p[100001]; int t=1; scanf("%d",&T); while(T--) { int ans=0; scanf("%d",&N); for(int i=1;i<=N;i++) scanf("%d",&p[i]); printf("Case #%d: ",t); t=t+1; sort(p+1,p+N+1,ac);//sort排序是从零开始的,所以+1才可使下表相符 for(int i=1;i<=N;i++) { if(i%3!=0) ans=ans+p[i]; } printf("%d\n",ans); } return 0;}
- The Third Cup is Free
- hdu 5999 The Third Cup is Free
- HDU 5999 The Third Cup is Free
- HDU5999-The Third Cup is Free
- HDU - 5999 The Third Cup is Free 贪心
- The Third Cup is Free
- HDU 5999—The Third Cup is Free
- This is the third time geekband
- The third
- The Free Lunch Is Over(译)
- The Free Lunch Is Over - Bombe
- Facebook Hacker Cup 2016 Qualification Round The Price is Correct
- THE THIRD CENTOS INSTALLATION
- The third week
- the third 实训课
- The third day
- The third (构造方法)
- The Third Day
- C++学习总结-1
- 人工智能(AI)第一节课总结
- JavaScript实现Fly Bird小游戏
- java并发(二)线程安全的实现方法
- windows下用git配置ssh实现无密码登录
- The Third Cup is Free
- 蛋疼的 POCO CppUnit
- Minimal BASH-like line editing
- Kotlin学习(二)基本语法
- Java并发工具总结
- 进程/线程->多线程
- rabbitmq从零学起
- hdu 2552 三足鼎立(简单数学)
- 读书笔记 effective c++ Item 16 成对使用new和delete时要用相同的形式