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. 使用PULL解析XML文件

    转载博文1:http://blog.csdn.net/wangkuifeng0118/article/details/7313241 XmlPull和Sax类似,是基于流(stream)操作文件,然后 ...

  2. 【BZOJ】1057: [ZJOI2007]棋盘制作(单调栈)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1057 同某一题差不多?记不清是哪题了.. 就是每一行进行单调栈维护递增的高度,在进栈和出栈维护一下长 ...

  3. storm的集群安装与配置

    storm集群安装 机器:(storm及zookeeper都是这3台机器) 192.168.80.20 192.168.80.21 192.168.80.22 须要准备的软件有: zookeeper( ...

  4. 【linux】硬盘分区

    fdisk -l fdisk /dev/sda d--删除分区 n-新建分区 p--主分区 e--扩展分区 t--改变分区格式 82为swap分区 w--保存退出 http://www.blogjav ...

  5. hdu 2686(状压dp)

    题目链接:http://poj.org/problem?id=2686 思路:典型的状压dp题,dp[s][v]表示到达剩下的车票集合为S并且现在在城市v的状态所需要的最小的花费. #include& ...

  6. python入门(九):网络编程和多线程

    一.网络编程 Socket简介 Socket又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求,使主机间或者一台计算机上的进程间可以通讯. ...

  7. 杂记之--如何把项目托管到GitHub上面

    参考了文顶顶大神的方法,这里仅做记录用! https://pan.baidu.com/s/1gfCaCXd

  8. Hadoop1.2.1 HDFS原理

    基本以图片的形式呈现给大家: .

  9. js获取格式化后的当前时间

    代码如下: function getFormatDate() { var day=new Date(); var Year=0; var Month=0; var Day=0; var Hour = ...

  10. AsyncTask--远程图片获取与本地缓存

    对于客户端——服务器端应用,从远程获取图片算是经常要用的一个功能,而图片资源往往会消耗比较大的流量,对应用来说,如果处理不好这个问题,那会让用户很崩溃,不知不觉手机流量就用完了,等用户发现是你的应用消 ...