HDU 5999
来源:互联网 发布:c语言中memcpy函数 编辑:程序博客网 时间:2024/06/06 01:55
题意:
T 组数据 , 每组数据 N 个数据 , 每个 数在1000以内。
买 N 个东西,买 2 送一 ,问买所有东西的最小话费。
思路:
排个序就行
代码:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int T,n,ans,a[(int)1e5+100]; while(scanf("%d",&T)!=-1){ for(int ppp=1;ppp<=T;ppp++){ ans=0; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); ans+=a[i]; } sort(a+1,a+n+1,greater<int>()); for(int i=3;i<=n;i+=3) ans-=a[i]; printf("Case #%d: %d\n",ppp,ans); } }}
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
limits
231 2 3510 20 30 20 20
Case #1: 5Case #2: 80
0 0
- HDU 5999
- HDU-5999
- hdu 5999
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- itunes中删除应用程序
- 来自微信团队的6个开源项目
- SAPUI5 ToolPage效果
- WUSTOJ 1878 金明的预算方案(有依赖的背包/树形DP)
- 动态规划
- HDU 5999
- 如何用U盘安装windows10操作系统
- 哈夫曼树
- Spring boot(三)
- 关于考试的总结
- 扫雷 HDU - 5965
- 汉诺(Hanoi)塔问题。将A座上的n个盘子移到C座上去,每次只能移动一个盘子,且必须保证大盘子在下,小盘子在上。
- Hibernate:入门简介
- H264编解码框架介绍