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 ...
随机推荐
- 最长递增子序列(LIS)(转)
最长递增子序列(LIS) 本博文转自作者:Yx.Ac 文章来源:勇幸|Thinking (http://www.ahathinking.com) --- 最长递增子序列又叫做最长上升子序列 ...
- Bzoj1939 [Croatian2010] Zuma
Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 43 Solved: 31 Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 ...
- 【leetcode 简单】 第五十六题 快乐数
编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...
- TIP协议
1. TIP是什么? CISCO给TIP的定义如下: The TIP protocol specifications describe how to multiplex multiple screen ...
- seq与Shell序列生成
有时候可能有这样的需要:用Shell生成类似0001这样的序列作为批次号,这里整理了一下个人的方法 方法一:通过seq命令 seq命令可以生成从某个数字到递增到另一数字的序列.用法如下: # seq ...
- 守卫者的挑战(guard)
problem Pro 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜寻着关押applepi的监狱的所在地.突然,眼前一道亮光闪过.“我,Nizem,是黑魔法圣殿的守卫者.如果你能通过 ...
- 【译】第三篇 Replication:事务复制-发布服务器
本篇文章是SQL Server Replication系列的第三篇,详细内容请参考原文. 发布服务器是所有复制数据的源头.每一个发布服务器上可以定义多个发布.每一个发布包含一组项目(项目在同一个数据库 ...
- Spring4笔记10--SSH整合1--Spring与Hibernate整合
SSH 框架整合技术: 1. Spring与Hibernate整合(对比Spring与JDBC模板): Service业务层代码和测试类都不变,添加实体类的映射配置文件: <?xml versi ...
- jQuery Validate自定义金钱验证,是否为金额格式,保留两位小数,并支持千分制货币格式
//自定义函数实现 isMoney: function (value, element){ // return this.optional(element) || /(^[1-9]([0-9]+)?( ...
- CodeForces 1096E: The Top Scorer
一道经典组合数学+容斥题. 题目传送门:CF1096E. 题意简述: \(p\) 个人,每个人有得分 \(a_i\). 总得分 \(\sum a_i = s\). 第一个人得分 \(a_1 \ge r ...