HDU 5999—The Third Cup is Free
来源:互联网 发布:工作日志管理系统php 编辑:程序博客网 时间:2024/05/22 08:16
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.
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.
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.
limits
231 2 3510 20 30 20 20
Case #1: 5Case #2: 80
题目大意:一个熊猫打算请他很多的朋友在咖啡馆里喝咖啡,咖啡馆有个优惠:买两杯咖啡,第三杯会免费。已知人数和每个所选的咖啡的价格,求熊猫最少只需花多少钱。
分析:一道明显的贪心题目,若要花钱最少,则只需免费的那些咖啡原价越贵越好,因此将所有咖啡的价格装进一个数组后从大到小排序,忽略第3及3的倍数杯咖啡的价格,然后统计总价即可。
AC代码:
#include <cstdio>#include <string>#include <cmath>#include <algorithm>#include <iostream>#include <vector>#include <queue>using namespace std;int p[100005];bool compare(int x,int y){ return x>y;}int main(){#ifdef LOCALfreopen("data.in","r",stdin);freopen("data.out","w",stdout);#endif int t; int sum; int kase=0; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&p[i]); sort(p,p+n,compare); sum=0; for(int i=0;i<n;i++) { if((i+1)%3==0) p[i]=0; sum+=p[i]; } printf("Case #%d: %d\n",++kase,sum); }return 0;}
0 0
- hdu 5999 The Third Cup is Free
- HDU 5999 The Third Cup is Free
- HDU 5999—The Third Cup is Free
- HDU - 5999 The Third Cup is Free 贪心
- The Third Cup is Free
- HDU5999-The Third Cup is Free
- The Third Cup is Free
- This is the third time geekband
- The third
- HDU——2289 Cup
- The Free Lunch Is Over(译)
- The Free Lunch Is Over - Bombe
- Facebook Hacker Cup 2016 Qualification Round The Price is Correct
- [hdu] CUP
- THE THIRD CENTOS INSTALLATION
- The third week
- the third 实训课
- The third day
- Android4种网络连接方式HttpClient、HttpURLConnection、OKHttp和Volley优缺点和性能对比
- 第十八章 SpringMVC @ControllerAdvice
- 使用live555类库实现的网络直播系统——直播H264文件
- Unity编程标准导引-3.4 Unity中的对象池
- ActiveMQ笔记(6):消息延时投递
- HDU 5999—The Third Cup is Free
- java随机生成6/8/12位数,要求每次产生的随机数与已生成的随机数不重复
- canvas动态获取视频第一帧 作为介绍
- 升级REVIT2016API填坑
- const int *p和int * const p的区别(常量指针与指向常量的指针)
- 第十九章 SpringMVC其它配置
- caffe:自己的数据训练模型 用于视频检索(一)
- Spring MVC与Struts2比较
- 使用jdGrid和Bootstrap实现的分页