1125 Chain the Ropes (25 分)

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

题目大意:给出好多段绳子,每两段绳子合并在一起就长度减半,求出可能的最大的长度。

//读了好几遍,没太懂啊 ,那就找输入的n个数里最大的两个数呗,那折叠之后不就是最长的了吗???

//似乎明白了,因为组合成的绳子可以再次被折叠,所以就有一个最优解的。

//我似乎理解错题意了,是要使用全部N条绳子才可以!

#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; int main(){
int n,t;
cin>>n;
//是哪个头文件里的???
priority_queue<int> pq;//使用优先队列存储
for(int i=;i<n;i++){
cin>>t;
pq.push(t);
}
int a,b,mlen=;
while(!pq.empty()){
a=pq.top();pq.pop();
b=pq.top();pq.pop();
int m=a/+b/;
if(m>mlen){
mlen=m;
}else break;
pq.push(m);
}
cout<<mlen;
return ;
}

//理解错误的题意。

柳神解答:

1.不过还是复习了优先队列的头文件要包括queue。

PAT 1125 Chain the Ropes[一般]的更多相关文章

  1. PAT 1125 Chain the Ropes

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

  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. opencv 摄像头人脸检测

    PYTHON ubuntu16.04 默认安装的Python版本2.7.12,当用pip install opencv-python 安装了opencv for python 3.3.0.10后,运行 ...

  2. SQL之Join的使用

    一.基本概念 关于sql语句中的连接(join)关键字,是较为常用而又不太容易理解的关键字,下面这个例子给出了一个简单的解释 –建表user1,user2: table1 : create table ...

  3. 工具类之Mutex

    Mutex在Android4.4的源代码包的./system/core/include/utils/Mutex.h中定义并且实现. 我们先复习一下Mutex在Linux中功能: Mutex出生的意义就 ...

  4. 如果没有指定Cookie的时效,那么默认的时效是。(选择1项)

    如果没有指定Cookie的时效,那么默认的时效是.(选择1项) A.一天 B. 永不过期 C.会话级别 D.一分钟 解答:C 这是API的原文:By default, -1 indicating th ...

  5. 嵌入式开发之gb281818

    http://www.cnblogs.com/snake-hand/p/3157176.html http://blog.csdn.net/voipmaker/article/category/140 ...

  6. php -- session会话

    PHP Sessions PHP session 变量用于存储关于用户会话(session)的信息,或者更改用户会话(session)的设置.Session 变量存储单一用户的信息,并且对于应用程序中 ...

  7. 【BZOJ】1500: [NOI2005]维修数列(splay+变态题)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1500 模板不打熟你确定考场上调试得出来? 首先有非常多的坑点...我遇到的第一个就是,如何pushu ...

  8. 【BZOJ】1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1639 同tyvj1359,http://www.cnblogs.com/iwtwiioi/p/394 ...

  9. 小结:bfs

    概要: 我们在初始状态要到达终止状态可以沿着同深度的向下搜索,这样范围覆盖更广,在解的深度较小的时候十分适用. 技巧及注意: 所有状态在转移后如果要打标记一定要在进队列前打!不要在出队列才打!否则就是 ...

  10. AWS系列-添加购买的https证书

    1.1 自行购买证书 1.2 上传证书 打开EC2的负载均衡 选择相应的ALB 添加侦听器 选择https 端口443 选择目标组 证书类型 上传证书到IAM 证书名称填写申请证书时候的那个域名 私有 ...