Source:

PAT A1125 Chain the Ropes (25 分)

Description:

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). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 1.

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

Keys:

Attention:

  • 依次把最小的结点相加即可
  • a1 < a2 < a3, 则(a1+a2)/2 < a3

Code:

 /*
Data: 2019-08-13 19:44:48
Problem: PAT_A1125#Chain the Ropes
AC: 14:23 题目大意:
两段绳子结在一起后长度减半
输入:
给出N段绳子及其长度
输出:
最大长度
*/
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e4+; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,r[M];
scanf("%d", &n);
for(int i=; i<n; i++)
scanf("%d", &r[i]);
sort(r,r+n);
for(int i=; i<n; i++)
r[] = (r[]+r[i])/;
printf("%d", r[]); return ;
}

PAT_A1125#Chain the Ropes的更多相关文章

  1. PAT1125:Chain the Ropes

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

  2. 1125 Chain the Ropes (25 分)

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

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

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

  4. PAT 1125 Chain the Ropes[一般]

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

  5. A1125. Chain the Ropes

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

  6. 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 ...

  7. 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 ...

  8. 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 ...

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

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

随机推荐

  1. 洛谷 P1796 汤姆斯的天堂梦_NOI导刊2010提高(05)

    P1796 汤姆斯的天堂梦_NOI导刊2010提高(05) 题目描述 汤姆斯生活在一个等级为0的星球上.那里的环境极其恶劣,每天12小时的工作和成堆的垃圾让人忍无可忍.他向往着等级为N的星球上天堂般的 ...

  2. JQuery获取select选中值和清除选中状态(转)

    1.获取值 var provinceSearch = $("#loc_province_search").find("option:selected").att ...

  3. 基于zookeeper和强一致性复制实现MySQL分布式数据库集群

    http://qikan.cqvip.com/article/detail.aspx?id=667750898&from=zk_search

  4. HIHO 16 B

    卡了~卡了就写不下去了~其实是不会~ 大牛提醒,答案必定是SUM的因子~细细想了好久,才想通~差距~ 因为是所有的和GCD,所以GCD必定整除SUM.. 然后,枚举这些因子,统计前缀和的MOD,看有多 ...

  5. 64位oracle数据库用32位plsql developer无法连接问题(无法载入oci.dll)

    在64位操作系统下安装oracle数据库,新下载了64位数据库(假设是32位数据库安装在64位的操作系统上,无论是client还是server端.都不要去选择C:\Program Files (x86 ...

  6. SpringMVC + MyBatis 配置文件

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...

  7. EMC 存储管理

    第一章EMC 产品介绍 1.1.         名词介绍 DAE——磁盘笼.用于装载磁盘的柜子. ◆Disk processor enclosure——含磁盘的控制器单元.存储系统的主要设备,内含存 ...

  8. c++调用DOS命令,不显示黑屏

    WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...

  9. E20170902-hm

    devise v. 设计; 想出; 发明; 策划;   n. 遗赠; 遗赠的财产; 遗赠的条款; device n. 设备  

  10. Django day06 模版层(二) 过滤器 标签

    一: 模板语言之过滤器: " | " 前后的区分: 前面的是函数的第一个参数, 后面的是python的一个函数, 冒号后面的是第二个参数例:  <p>过滤器之默认值:{ ...