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 ...
随机推荐
- 当今最流行的Web项目管理工具精选
代码管理 以前各种开源项目的代码都是通过博客和个人网页来发布的.这种分享方式并不是最容易的一种,也不便于他人对代码做出贡献.下面是几个管理项目代码的工具,不管对于个人开发者还是团队开发者来说,它们都是 ...
- thinkphp 修改分页样式表
原网页:http://blog.csdn.net/u014175572/article/details/53116546 在这里我有先把page的设置做成了一个函数getpage, 将这个方法放到Ap ...
- Django认证系统实现的web页面
结合数据库.ajax.js.Djangoform表单和认证系统的web页面 一:数据模块 扩展了Django中的user表,增加了自定义的字段 from django.db import models ...
- php strcmp()函数
<? $str = "LAMP"; $str1 = "LAMPBrother"; $strc = strcmp($str,$str1); switch ( ...
- Java并发编程(2) AbstractQueuedSynchronizer的内部结构
一 前言 虽然已经有很多前辈已经分析过AbstractQueuedSynchronizer(简称AQS,也叫队列同步器)类,但是感觉那些点始终是别人的,看一遍甚至几遍终不会印象深刻.所以还是记录下来印 ...
- Hibernate5笔记3--详解Hibernate的API
详解Hibernate的API: (1)Configuration接口: org.hibernate.cfg.Configuration接口的作用是加载主配置文件及映射文件,以实现对Hibernate ...
- 更改arch的默认终端
实在是厌倦了gnome的资源管理器nautilus和终端gnome-terminal,于是卸载之,然后更换了xfce4的终端,但是出现了一个问题,那就是在资源管理器中使用邮件打开终端的时候打不开了,解 ...
- 【技巧总结】Penetration Test Engineer[5]-Operating System Security(SQL Server、MySQL提权)
4.数据库安全基础 4.1.MSSQL 数据库角色权限 sysadmin:执行SQL Server中的任何动作 db_owner:可以执行数据库中技术所有动作的用户 public:数据库的每个合法用户 ...
- Interval Minimum Number
Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. ...
- Python基础二(输入与输出)
通常,一个程序都会有输入/输出,这样可以与用户进行交互.用户输入一些信息,你会对他输入的内容进行一些适当的操作,然后再输出给用户想要的结果.Python的输入/输出,我们可以用input进行输入,pr ...