【PAT甲级】1125 Chain the Ropes (25分)

题意:

输入一个正整数N(2<=N<=10000)表示绳子的根数,接着输入N个正整数(<=1000)表示每根绳子的长度,每两根绳子可以结成一根新绳子,之后它们的长度变为原来的一半,求将所有绳子结为一根绳子以后的最长长度,结果舍入。

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int a[10007];
 5 int main(){
 6     ios::sync_with_stdio(false);
 7     cin.tie(NULL);
 8     cout.tie(NULL);
 9     int n;
10     cin>>n;
11     for(int i=1;i<=n;++i)
12         cin>>a[i];
13     sort(a+1,a+1+n);
14     int ans=a[1]+a[2];
15     ans/=2;
16     for(int i=3;i<=n;++i)
17         ans=(ans+a[i])/2;
18     cout<<ans;
19     return 0;
20 }

 

posted @ 2020-03-12 22:04  sewage  阅读(109)  评论(0编辑  收藏  举报