A1125. Chain the Ropes
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 <= 104). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 104.
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<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
double rope[];
int N;
int main(){
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%lf", &rope[i]);
}
sort(rope, rope + N);
double ans = rope[];
for(int i = ; i < N; i++){
ans += rope[i];
ans = ans / 2.0;
}
int prt = ans;
printf("%d", prt);
cin >> N;
return ;
}
题意: 两段绳子可以合并成一段,但它们一合并,新绳子的长度就会变为原来两绳之长的和的一半,求能得到的最长的绳子。显然越早合并的绳子被1/2的次数就越多,所以要让越长的绳子尽量最后合并。
A1125. Chain the Ropes的更多相关文章
- 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 ...
- PAT_A1125#Chain the Ropes
Source: PAT A1125 Chain the Ropes (25 分) Description: Given some segments of rope, you are supposed ...
- 1125 Chain the Ropes (25 分)
1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...
- PAT1125:Chain the Ropes
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT甲级 1125. Chain the Ropes (25)
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT 1125 Chain the Ropes[一般]
1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...
- 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 ...
- 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 ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
随机推荐
- VUE 处理文本框获焦点高亮
先贴例子代码 这里又三个div对应的三个input输入框 <!-- 登录的表单 --> <div class="input_group" :class=&quo ...
- git修改用户名、邮箱
在windows使用git命令方法如下(以win7为例):1.msysgit 是 Windows 版的 Git可以百度搜索Git下载.2.安装完成后,开始菜单里找到“Git”->“Git Bas ...
- python爬虫之git的安装
一.初始 1.发展历史 *最开始没有对代码的管理,导致很多东西混乱和丢失. *后来大家想了一个办法,用最简单最笨的方法,各种复制文件夹. *然后就出现了版本控制的工具. 1.单机版:RCS(198 ...
- 老男孩python学习自修第二十四天【多进程】
1. 体验多进程的运行速度 #!/usr/bin/env python # _*_ coding:UTF-8 _*_ from multiprocessing import Pool import t ...
- Bootstrap之响应式导航栏
代码: <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8 ...
- The Bug and Exception of Hibernate
1: hibernate4.3.5 的@oneToOne注解有Bug,建议不使用该版本,或者使用该版本不使用@table annotation. 2:今天在用hibernate4.2.13的时候, ...
- JUC虚假唤醒(六)
为什么条件锁会产生虚假唤醒现象(spurious wakeup)? 在不同的语言,甚至不同的操作系统上,条件锁都会产生虚假唤醒现象.所有语言的条件锁库都推荐用户把wait()放进循环里: whil ...
- maven 当两个工程合并后 他的classpath也合并了
maven 当两个工程合并后 他的classpath也合并了 也就是说资源文件环境合并了
- Random Processes
对于信号处理来说,有一类信号是非常重要的,这类信号就是随机信号(random signal),也被称为随机过程(random processes/stochastic processes).在各种书籍 ...
- 因为网络安全的重要性打算学习linux
互联网的普及,在给人们带来巨大便利的同时,也让人们感受到网络安全隐患带给人们的不安与威胁.尤其是随着计算机技术和网络技术应用范围的不断扩充,网络安全方面存在的漏洞也越来越多,在这种情况下,如何提高网络 ...