poj 3253 fence repair
来源:互联网 发布:华为手机游戏数据 编辑:程序博客网 时间:2024/05/22 10:43
/* poj 3253 fence repair 题意是说有一个人想要修东西,需要去将一根木头砍成N 段长度指定的木头,现在给定这根木头需要的长度集合 问最少花费是多少 算法设计:贪心的去选择较短的合成,每次都选择最短的两条 最后合成一根木头,也就是还原成原来的总长度*/#include<iostream>#include<queue>#include<functional>using namespace std;typedef long long ll;int N;void solve(){ll ans = 0;priority_queue<int, vector<int>, greater<int> >que;for (int i = 0; i < N; i++){int in;cin >> in;que.push(in);}//input donewhile (que.size()>1){int t1, t2;t1 = que.top(),que.pop();t2 = que.top(), que.pop();ans += t1 + t2;que.push(t1+t2);}cout << ans << endl;}int main(){while (cin >> N){solve();}return 0;}
0 0
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- POJ 3253Fence Repair
- POJ--3253 -- Fence Repair
- poj-3253-Fence Repair
- POJ 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253 Fence Repair
- POJ - 3253 Fence Repair
- POJ 3253 Fence Repair
- poj 3253 Fence Repair
- poj 3253---Fence Repair
- windows程序设计 消息循环
- unity3D C#简单代理使用了解
- django操作数据库问题总结
- poj3910欧拉函数的矩阵应用
- windows程序设计 窗口过程函数
- poj 3253 fence repair
- C标准库:以串为单位的IO函数
- 查看版本 - Ubuntu
- 筛选欧拉数n
- Java基础(18,19(1))IO流
- 关于Android中的strings.xml的一些其他用法
- 3.24
- ++i & i++
- qt 使用 pythonqt报错python34_d.lib