题目链接
点击打开链接
思路
由于没结一次,就要缩短一半,因此越长的结的越少,那最后总长度肯定最长。于是把输入递增排序,然后逐个结绳就行了。
代码
#include <stdlib.h>
#include <stdio.h>
void quick_sort(int a[],int start,int end){
int i,j,temp;
i = start;
j = end;
temp = a[i];
if(i <j){
while(i<j){
while(i<j && a[j]>=temp)j--;
a[i] = a[j];
while(i<j && a[i]<=temp)i++;
a[j] = a[i];
}
a[i] = temp;
quick_sort(a,start,i-1);
quick_sort(a,i+1,end);
}
}
int main(){
int i,N,img[10001];
double temp = 0.0;
scanf("%d",&N);
for(int i = 0;i<N;i++){
scanf("%d",&img[i]);
}
quick_sort(img,0,N-1);
for(temp = img[0],i =1;i<N;i++){
temp +=img[i];
temp /=2;
}
printf("%d",(int)temp);
return 0;
}