Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulting chain will be treated as another segment of rope and can be folded again. After each chaining, the lengths of the original two segments will be halved.

Your job is to make the longest possible rope out of N given segments.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (2≤N≤10^​4 ). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 10^​4 .

Output Specification:

For each case, print in a line the length of the longest possible rope that can be made by the given segments. The result must be rounded to the nearest integer that is no greater than the maximum length.

Sample Input:

8

10 15 12 3 4 13 1 15

Sample Output:

14

#include<iostream> //水题
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n, ans=0;
cin>>n;
vector<int> data(n, 0);
for(int i=0; i<n; i++)
cin>>data[i];
sort(data.begin(), data.end());
ans=data[0];
for(int i=1; i<n; i++)
ans=(ans+data[i])/2;
cout<<ans<<endl;
return 0;
}

PAT 1125 Chain the Ropes的更多相关文章

  1. PAT 1125 Chain the Ropes[一般]

    1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...

  2. PAT甲级 1125. Chain the Ropes (25)

    1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  3. 1125 Chain the Ropes (25 分)

    1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...

  4. PAT甲题题解-1125. Chain the Ropes (25)-贪心水题

    贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...

  5. 1125. Chain the Ropes (25)

    Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...

  6. 1125 Chain the Ropes

    题意:略. 思路:思考一下,最先拿去对折的绳子会参与之后的每次对折,而对一条绳子而言,对折的次数越多剩下的就越短,因此,要让最终的结果尽可能长,应该先让较短的绳子先对折. 代码: #include & ...

  7. PAT1125:Chain the Ropes

    1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  8. PAT_A1125#Chain the Ropes

    Source: PAT A1125 Chain the Ropes (25 分) Description: Given some segments of rope, you are supposed ...

  9. PAT甲级——A1125 Chain the Ropes【25】

    Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...

随机推荐

  1. CodeForces 124C Prime Permutation (数论+贪心)

    题意:给定一个字符串,问你能不能通过重排,使得任意一个素数p <= 字符串长度n,并且 任意的 i <= 长度n/素数p,满足s[p] == s[p*i]. 析:很容易能够看出来,只要是某 ...

  2. P2600 [ZJOI2008]瞭望塔

    传送门 暴力也行,退火也行,不是很明白为啥还要用半平面交-- 总之就是把原来的所有限制看成一堆半平面 根据黄学长的博客塔肯定建在转折处最优 //minamoto #include<bits/st ...

  3. npm更换为淘宝镜像源

    1.通过config命令   1 2 npm config set registry http://registry.cnpmjs.org npm info underscore (如果上面配置正确这 ...

  4. robotframework - Edit编辑器

    1.测试项目&套件 提供的Edit编辑器 2.在 Edit 标签页中主要分:加载外部文件.定义内部变量.定义元数据等三个部分. (1):加载外部文件Add Library:加载测试库,主要是[ ...

  5. crosswalk 初步使用

    这里简单的说下 crossWalk 的配置; 我在学习 crosswalk 的时候,看到一篇博客,他所记录的已经是很完整的教程了: 点击查看 本文就根据该博客和官网说明,进行部分修改,补充; 首先 c ...

  6. 我的周记2——“天道酬勤"

    Get 什么是JAVA  https://zhuanlan.zhihu.com/p/62717204 了解下HTTP 缓存机制 https://juejin.im/post/5a1d4e546fb9a ...

  7. n阶完全生成图的数量

    有些事不是看到了希望才去坚持,而是坚持了才会看到希望 问题 I: 星际之门(一) 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 公元3000年,子虚帝国统 ...

  8. 2、ipconfig命令

    该命令能够显示出正在使用的计算机的IP信息情况.这些信息包括IP地址.子网掩码.默认网关(连接本地计算机与Internet的计算机).通过IP地址可以进行扫描.远程管理.入侵检测等.ipconfig命 ...

  9. Windows Install Twisted 安装Twisted

    1.下载twisted exe https://twistedmatrix.com/Releases/Twisted/15.4/ (注意最新版16.x没有适用于windows的exe,只能用旧版) 2 ...

  10. malloc()函数的使用

    malloc是向系统申请分配指定size个字节的内存空间.返回值类型为void *类型.void *表示未确定的类型指针.C语言中,void *类型可以强制转换为任何其他类型的指针. 语法:void ...