POJ 3253 Fence Repair
来源:互联网 发布:软件报价方案模板 编辑:程序博客网 时间:2024/06/06 21:36
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int a[20002];
for (int i = 0; i < n; i++)
cin >> a[i];
if (n == 1)
{
cout << a[0] << endl; continue;
}
sort(a, a + n);
long long sum = 0;
while (n > 1)
{
int j = 0, k = 1;
if (a[0] > a[1]) swap(j,k);
for (int i = 2; i < n; i++)
{
if (a[i] < a[j])
{
k = j, j = i;
}
else if (a[i] < a[k])
k = i;
}
sum = sum + a[j] + a[k];
if (j == n - 1) swap(j, k);
a[j] = a[j] + a[k];
a[k] = a[n - 1]; n--;
}
cout << sum << endl;
}
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
- 那些年我们学过的排序算法
- Java线程泄露的分析与处理
- Thread的中断机制(interrupt)
- 小白使用React---ajax请求成功后跳转到另一个页面
- C++主动调用析构函数分析
- POJ 3253 Fence Repair
- bzoj4025二分图 线段树分治+并查集
- 设计一个动物声音模拟器,希望模拟器可以模拟许多动物的叫声
- C# 获取本地电脑所有的盘符
- 【DFS】BZOJ1024(SCOI2009)[生日快乐]题解
- C到C++
- 23种设计模式(5)-适配器模式
- LeetCode简易题解--091
- vue 父组件和子组件的通信