1125 Chain the Ropes

1125 Chain the Ropes

题目大意:

两个绳子结合成一个绳子总长度会减半,现在给你n条绳子把他们连接成一条,输出最长的方案的长度。

解题思路:

排序,从小到大一个一个连就好了,因为从小到大连损失的长度最少。、
代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n,rope[11000]={0};
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&rope[i]);
	sort(rope,rope+n);
	int sum=(rope[0]+rope[1])/2;
	for(int i=2;i<n;i++)
	{
		sum=(sum+rope[i])/2;
	}
	cout<<sum<<endl;
}