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

分析:贪心题,自己做的时候直接排序然后从小开始两两对折最后输出结果就AC了,但不知道原因。。(做贪心有时候就凭感觉,没有严格证明)。后来看柳神题解才恍然大悟,若从大的开始对折,每次对折损耗会更多,而从小的开始损耗的就越少。比如10000,100,10,1,我从10000开始对折的话总共对折3次,相当于会损耗大的部分3次,如果最后再对折就损耗少了!

 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-28-13.41.03
 * Description : A1125
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 int a[maxn];
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n;
     scanf("%d",&n);
     ;i<n;i++){
         scanf("%d",&a[i]);
     }
     sort(a,a+n);
     ];
     ;i<n;i++){
         sum=(a[i]+sum)/;
     }
     cout<<int(sum);
     ;
 }
 

1125 Chain the Ropes (25 分)的更多相关文章

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

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

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

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

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

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

  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 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)

    1079 Total Sales of Supply Chain (25 分)   A supply chain is a network of retailers(零售商), distributor ...

随机推荐

  1. 20165313 《Java程序设计》第一周学习总结

    教材学习内容总结 1.Java的地位 1.网络地位 2.语言地位 3.需求地位 2.Java的特点 1.简单 2.面向对象 3.平台无关 4.多线程 5.动态 3.安装JDK(重点) 注释:需修改系统 ...

  2. hdu4990 Reading comprehension 矩阵快速幂

    Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:10240 ...

  3. LNMP环境包安装IonCube教程

    ioncube是业内优秀的php加密解密解决方案.和zend guard相比,ioncube具有如下优势: 1. 安全:zend guard的版本不是非常安全,网络上有破解使用zend,下面我们来看I ...

  4. 【HAOI2016】放旗子

    终于自己推出来一道题了quq然而时间有点久,考场上并不大丈夫……原题: 给你一个N*N的矩阵,每行有一个障碍,数据保证任意两个障碍不在同一行,任意两个障碍不在同一列,要求你在这个矩阵上放N枚棋子(障碍 ...

  5. 【mybatis源码学习】调试mybatis的第一个程序

    [一].基础知识准备 mybatis-config.xml配置文件的结构 MyBatis配置文件中大标签configuration下子标签包括: configuration |--- properti ...

  6. 用Python开发Zeroc Ice应用

    Zeroc Ice简介   Zeroc ICE(Internet Communications Engine ,互联网通信引擎)是目前功能比较强大和完善的RPC框架,支持跨平台.跨语言调用.它非常灵活 ...

  7. linux服务器进程信息查看命令

    #lsof 列出当前系统打开文件,常与-i选项使用,用于查看某个端口被哪个程序占用 [root@bogon ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE ...

  8. phpstorm 2017激活码(方法)

    JetBrains激活 JetBrains 授权服务器(License Server URL):http://idea.imsxm.com 使用方法:激活时选择License server 填入htt ...

  9. 开源自然语言处理工具包hanlp中CRF分词实现详解

     CRF简介 CRF是序列标注场景中常用的模型,比HMM能利用更多的特征,比MEMM更能抵抗标记偏置的问题. [gerative-discriminative.png] CRF训练 这类耗时的任务,还 ...

  10. VS未能正确加载包

    这个方法同样适用于多个版本的VS 首先关闭VS进这里:C:\Users\用户名\AppData\Roaming\Microsoft\VisualStudio\11.0(2012是11.0,根据你的VS ...