GYM 101128 C.Canvas Painting(优先队列)
来源:互联网 发布:windows ime文件 编辑:程序博客网 时间:2024/04/30 20:30
Description
给n件白色货物染色,先把这些货物按顺序放好,然后选定一个颜色C和一个数量F,之后把前F个颜色为C的货物染成X颜色,把剩余的颜色为C的货物染成Y颜色,X和Y是与所有出现过的颜色不用的两种不同颜色,问最少需多少颜料才能把每件货物都染上不同颜色
Input
第一行一整数T表示用例组数,每组用例首先输入一整数n表示货物数量,之后输入n个整数a[i]表示给第i件货物染色需要多少颜料(1<=T<=100,1<=n<=100000,1<=a[i]<=100000,1<=sum{n}<=100000}
Output
对于每组用例,输出一整数表示给所有货物染上不同颜色所需的最少颜料数
Sample Input
2
3
7 4 7
4
5 3 7 5
Sample Output
29
40
Solution
合并果子变形,因为可以自定义顺序,倒过来看染色,每次就是把两种不同颜色的合并染成另一种颜色,代价是所需颜料之和
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>#include<functional>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 111111int T,n;priority_queue< ll,vector<ll>,greater<ll> >que;int main(){ scanf("%d",&T); while(T--) { scanf("%d",&n); while(!que.empty())que.pop(); for(int i=1;i<=n;i++) { int a; scanf("%d",&a); que.push(a); } ll ans=0; while(que.size()>1) { ll a=que.top();que.pop(); ll b=que.top();que.pop(); a+=b; ans+=a; que.push(a); } printf("%I64d\n",ans); } return 0;}
0 0
- GYM 101128 C.Canvas Painting(优先队列)
- GYM 101128 C.Canvas Painting【思维+优先队列】
- Canvas Painting Gym
- Gym Class(优先队列+拓扑排序)
- hdu5695(拓扑+优先队列)Gym Class
- Gym 101617Jbfs+优先队列
- HDU-5695-Gym Class(拓扑排序+优先队列)
- HDU 5695 Gym Class(优先队列+拓扑排序)
- HDU 5695 Gym Class (拓扑排序+优先队列+Vector)
- HDU 5695 Gym Class(拓扑排序,优先队列)
- HDU:5695 Gym Class(拓扑排序+优先队列)
- GYM 100090 I.Retakes(贪心+优先队列)
- Gym Class(拓扑排序+vecteor+优先队列)-HDU5965
- 优先队列(C++/Java)
- HDU5695:Gym Class(优先队列+拓扑排序)
- hdu5695-优先队列&拓扑排序-Gym Class
- 2016"百度之星" - 初赛(Astar Round2A)1006 Gym Class(优先队列+拓扑排序)
- Codeforces Gym 100792K King's Rout(优先队列+拓扑排序)
- 【高性能JavaScript】读书笔记
- hadoop 层面性能调优
- codeforces721A
- 第一天学习MySql(1)-从创建到删除
- TCP网络编程中connect()、listen()和accept()三者之间的关系
- GYM 101128 C.Canvas Painting(优先队列)
- EditPlus修改成护眼色
- hibernate进阶学习笔记
- 范式简介
- 使用AngularJS完成一个简单的todoList
- SQL教程重温
- windows中安装MySQL绿色社区版(5.7.17-winx64)
- 我的软件工程课目标
- Android扫描SD卡或者SD下某个文件夹得到想要的文件