POJ 3253
来源:互联网 发布:李洪成排盘软件下载 编辑:程序博客网 时间:2024/06/10 11:49
#include<cstdio>const int maxn = 40000+5;int L[maxn];int N;void swap(int& a, int& b){ int c = a; a = b; b = c;}void solve(){ long long ans = 0; //求出最短的板m1和倒数第二短的板m2 while(N > 1){ int m1 = 0, m2 = 1; if(L[m1] > L[m2]) swap(m1, m2); for(int i = 2; i < N; i++){ if(L[i] < L[m1]){ m2 = m1; m1 = i; } else if(L[i] < L[m2]){ m2 = i; } } //将两板拼合起来 int t = L[m1] + L[m2]; ans += t; if(m1 == N-1) swap(m1, m2); L[m1] = t; L[m2] = L[N-1]; N--; } printf("%lld\n", ans);}int main(){ while(scanf("%d", &N) == 1){ getchar(); for(int i = 0; i < N; i++){ scanf("%d", &L[i]); getchar(); } solve(); } return 0;}
阅读全文
0 0
- POJ 3253
- poj 3253
- poj 3253
- poj 3253
- poj----3253
- poj.3253
- poj 3253
- POJ 3253
- poj 3253
- poj-3253
- POJ-3253
- POJ 3253
- poj 3253
- poj-3253
- poj-3253
- POJ 3253
- POJ 3253
- POJ 3253
- int x/*test*/y;的结果是?
- 自定义标题栏
- html旋转动画
- App瘦身
- response对象的使用
- POJ 3253
- 声明和定义
- 单例模式的C#实现
- java线程池的总结
- c# 文件操作
- 转自mbxc816 欧拉函数递推
- 莫(bao)队(li)算法
- 如何把一个单例模式写出花来
- 通过Android.mk文件在源码下生成jar