HDU - 5999 The Third Cup is Free 贪心 简单题
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
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
∙
1 ≤ T ≤ 100.
∙
1 ≤ N ≤ 105.
∙
1 ≤ pi ≤ 1000.
3
1 2 3
5
10 20 30 20 20
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 贪心 简单题的更多相关文章
- cf 605A Sorting Railway Cars 贪心 简单题
其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i], ...
- 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 ...
- POJ 2393 贪心 简单题
有一家生产酸奶的公司,连续n周,每周需要出货numi的单位,已经知道每一周生产单位酸奶的价格ci,并且,酸奶可以提前生产,但是存储费用是一周一单位s费用,问最少的花费. 对于要出货的酸奶,要不这一周生 ...
- HDU 1316 How Many Fibs?(java,简单题,大数)
题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...
- HDU - 2199 Can you solve this equation? 二分 简单题
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- POJ 2260 Error Correction 模拟 贪心 简单题
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6825 Accepted: 4289 ...
- hdu2187悼念512汶川大地震遇难同胞——老人是真饿了(贪心 简单题)
传送门 简单题 #include<bits/stdc++.h> using namespace std; struct node { double dan,weight; }a[]; bo ...
- 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 ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
随机推荐
- HDU1693 Eat the Trees(zerojudge a228)
传送门: https://zerojudge.tw/ShowProblem?problemid=a228 http://acm.hdu.edu.cn/showproblem.php?pid=1693 ...
- Token报错问题
解决token报错,CSRF令牌问题: <form method="POST" action=""> {{ csrf_field() }} < ...
- 编程语言BrainkFuck
BrainFuck由Urban Müller在1993年创建,是经常被吐槽的语言,不过我觉得除了名字其它都还挺正常的,没错我觉得这个语言设计的很正常没有Fuck到我的脑子,大概是因为我根本就没有脑子吧 ...
- Postman和Selenium IDE开局自带红蓝BUFF属性,就问你要还是不要
话不多说,下面给大家介绍两款工具,selenium IDE和Postman. 为什么说是自带红蓝Buff,因为想做UI自动化和接口自动化的同学,很多时候,都难在了开头. 比如你要学习语言,你要学习框架 ...
- 【codeforces】【比赛题解】#862 CF Round #435 (Div.2)
这次比赛打得很舒服,莫名得了个Rank41,涨了219的Rating,就比较优秀.不过还是没有闫神厉害啊.题目链接::P. [A]MEX 题意: Evil博士把Mahmoud和Ehab绑架到了邪恶之地 ...
- git本地分支和远程分支改名
#1 将本地分支进行改名 git branch -m old_branch new_branch #2 将远程分支的老分支删除 git push origin :old_branch #3 将改名后的 ...
- Mac上删除不了的文件,Windows上也粉碎不了怎么办?
推荐一个Mac上的软件:Tuxera Disk Manager 用法很简单:选择删除文件原来所在的文件进行维护就可以了. 维护之后,在废纸篓中清除,成功.
- MongoDB安全:内置角色概览
官文列举如下(文档不长,过英语四级者可以轻松阅读,就不需要看本文额)(基于MongoDB 3.6的文档,4.0也没有变化): Role-Based Access Control Built-In Ro ...
- Linux下配置Samba服务器全过程
Linux下配置Samba服务器全过程 user级别的samba的配置 http://www.linuxidc.com/Linux/2014-11/109234.htm http://www.linu ...
- Java KeyStore 用命令生成keystore文件自己生成证书,简介
1.生成keyStore文件 在命令行下执行以下命令: Shell代码 收藏代码 keytool -genkey -validity 36000 -alias www.zlex.org -keyalg ...