hdu Problem-1678(priority_queue+模拟)
来源:互联网 发布:mac格式化u盘 什么格式 编辑:程序博客网 时间:2024/05/29 05:03
Shopaholic
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3117 Accepted Submission(s): 1706
Problem Description
Lindsay is a shopaholic. Whenever there is a discount of the kind where you can buy three items and only pay for two, she goes completely mad and feels a need to buy all items in the store. You have given up on curing her for this disease, but try to limit its effect on her wallet.
You have realized that the stores coming with these offers are quite elective when it comes to which items you get for free; it is always the cheapest ones. As an example, when your friend comes to the counter with seven items, costing 400, 350, 300, 250, 200, 150, and 100 dollars, she will have to pay 1500 dollars. In this case she got a discount of 250 dollars. You realize that if she goes to the counter three times, she might get a bigger discount. E.g. if she goes with the items that costs 400, 300 and 250, she will get a discount of 250 the first round. The next round she brings the item that costs 150 giving no extra discount, but the third round she takes the last items that costs 350, 200 and 100 giving a discount of an additional 100 dollars, adding up to a total discount of 350.
Your job is to find the maximum discount Lindsay can get.
You have realized that the stores coming with these offers are quite elective when it comes to which items you get for free; it is always the cheapest ones. As an example, when your friend comes to the counter with seven items, costing 400, 350, 300, 250, 200, 150, and 100 dollars, she will have to pay 1500 dollars. In this case she got a discount of 250 dollars. You realize that if she goes to the counter three times, she might get a bigger discount. E.g. if she goes with the items that costs 400, 300 and 250, she will get a discount of 250 the first round. The next round she brings the item that costs 150 giving no extra discount, but the third round she takes the last items that costs 350, 200 and 100 giving a discount of an additional 100 dollars, adding up to a total discount of 350.
Your job is to find the maximum discount Lindsay can get.
Input
The first line of input gives the number of test scenarios, 1 <= t <= 20. Each scenario consists of two lines of input. The first gives the number of items Lindsay is buying, 1 <= n <= 20000. The next line gives the prices of these items, 1 <= pi <= 20000.
Output
For each scenario, output one line giving the maximum discount Lindsay can get by selectively choosing which items she brings to the counter at the same time.
Sample Input
16400 100 200 350 300 250
Sample Output
400
//思路:简单模拟一下就行
AC源码:
#include <queue>#include <iostream>using namespace std;int main(){int T,n,tmp;cin>>T;while(T--){int ans=0;priority_queue<int,vector<int>,less<int> > pri;cin>>n;while(n--){cin>>tmp;pri.push(tmp);}while(1){int i=0;while(!pri.empty()){pri.pop();i+=1;if(i==2)break;}if(!pri.empty()){ans+=pri.top();pri.pop();}elsebreak;}cout<<ans<<endl;}return 0;}
阅读全文
0 0
- hdu Problem-1678(priority_queue+模拟)
- HDU-5867 Water problem(模拟)
- hdu 1022 Train Problem I 栈模拟
- hdu 2522 A simple problem(模拟)
- HDU 5373 The shortest problem //模拟
- hdu 5373 The shortest problem(模拟)
- hdu 5373 The shortest problem (模拟)
- hdu 5373 The shortest problem (模拟)
- Travelling Salesman Problem (hdu 5402 模拟)
- HDU-5402 Travelling Salesman Problem(模拟)
- hdu 5402 Travelling Salesman Problem 模拟构造
- hdu 5402 Travelling Salesman Problem(构造+模拟)
- HDU 5615:Jam's math problem【模拟】
- HDU 5867 Water problem (模拟)
- HDU 5920 Ugly Problem(模拟)
- HDU 5920 Ugly Problem(大数减法 模拟)
- HDU 5867 Water problem——模拟
- hdu Problem-1896(优先队列+模拟)
- 关于接下来的Android学习(一)
- bzoj 1054: [HAOI2008]移动玩具.cpp
- 对比一下PHP和JAVA开发网站的优劣
- 移植QT5.6到嵌入式开发板(史上最详细的QT移植教程)
- csu1006:SAW
- hdu Problem-1678(priority_queue+模拟)
- 【Learning Notes】基于 boosting 原理训练深层残差神经网络
- Web开发的概述总结
- 梳理shiro验证权限的思路
- 23. 编写函数:从num各字符串中找出最长的一个字符串,并通过形参指针max传回该串地址。
- mybatis分页插件PageHelper的使用
- AngularJs 的使用之双向绑定和指令
- 关于视频播放
- Redis源码剖析和注释(二十八)--- Redis 事务实现和乐观锁