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. 4. extjs中form中的frame:true表示什么

    转自:https://blog.csdn.net/qiu512300471/article/details/23737217 设置为true时可以为panel添加背景色.圆角边框等,如下图 下面的是f ...

  2. unable to unroll loop 报错

    unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations) 原本代码 f ...

  3. bzoj1076: [SCOI2008]奖励关(期望dp+状压dp)

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2989  Solved: 1557[Submit][Statu ...

  4. js获取标签的三种方式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. [Qt Creator 快速入门] 第3章 窗口部件

    从这一章开始正式接触Qt的窗口部件.在第2章曾看到 Qt Creator 提供的默认基类只有 QMainWindow.QWidget 和 QDialog 这3种.QMainWindow 是带有菜单栏和 ...

  6. 【洛谷3345_BZOJ3924】[ZJOI2015]幻想乡战略游戏(点分树)

    大概有整整一个月没更博客了 -- 4 月为省选爆肝了一个月,最后压线进 B 队,也算给 NOIP2018 翻车到 316 分压线省一这个折磨了五个月的 debuff 画上了一个不算太差的句号.结果省选 ...

  7. 292 Nim Game Nim游戏

    您和您的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 到 3 块石头. 拿掉最后一块石头的人就是胜利者.由您来开局.你们两个都是聪明人,相信都有最佳的游戏策略. 请编写一个函 ...

  8. keystore找回密码

    昨天准备给自己的应用发布一个新版本,在apk打包时,发现之前的用的keystore密码忘了. 蛋碎了一地,我把我所能想到的密码都试了一遍(注:我平常在各个门户网站注册基本上用的都是那几个字母和数字组合 ...

  9. [转]我要学ASP.NET MVC 3.0(十二): MVC 3.0 使用自定义的Html控件

    本文转自:http://www.cnblogs.com/lukun/archive/2011/08/05/2128693.html 概述   在ASP.NET MVC框架中已经封装了很多基于Html标 ...

  10. ch1 About thinking skills

    When confronted with a problem , we think about it. The issue, of course, is that our efforts may be ...