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. 安装部署redis3.2 phpRedisAdmin 攻略

    1.下载redis3.2稳定版本: 下载地址:  https://redis.io/download 2.安装: 解压文件后,进行文件夹: 执行以下命令: make cd src make insta ...

  2. whmcs模板路径

    whmcs网站根目录 比如你的域名是server.nongbin.vip,你需要cd /home/wwwroot/server.nongbin.vip,该目录下然后,cd template/ 给文件夹 ...

  3. oracle数据库丢失数据文件、控制文件、重做日志文件、初始化文件恢复方法

    rman  target/ list backup; 查看是否已备份,如果没有,那就不知道了 模拟故障,删除/u01/app/oracle/oradata/ORCL文件夹下的所有文件 sqlplus ...

  4. linux日志管理

    //有关当前登录用户的信息记录在文件utmp中 //登录进入和退出纪录在文件wtmp中 [root@bogon python]# who //who命令查询utmp文件并报告当前登录的每个用户 /va ...

  5. MySQL Execution Plan--数据排序操作

    MySQL数据排序 MySQL中对数据进行排序有三种方式:1.常规排序(双路排序)2.优化排序(单路排序)3.优先队列排序 优先队列排序使用对排序算法,利用堆数据结构在所有数据中取出前N条记录. 常规 ...

  6. 嵌入式LINUX设置时间

    date -s "2018-12-15 08:55:00" 安装NTP从网络获取时间 基于Linux的嵌入式开发,需要用到本地的时间,但是网上找了很多修改时间的命令,但大多是Lin ...

  7. powerdesigner-ER图建模

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...

  8. spring-boot-dependencies jar 不完整的问题

    集成 springboot 有两种方式. 1 直接 父项目指向  springboot <parent> <groupId>org.springframework.boot&l ...

  9. thinkphp5 怎么获取当前的模块,控制器和方法名

    //当前模块url地址 $request= Request::instance(); $module_name=$request->module(); $controller_name=$req ...

  10. java 迭代

    迭代器的作用是提供一种方法对一个容器对象中的各个元素进行访问,而又不暴露该对象容器的内部细节. java中的很多容器都实现了Iterable接口,容器中的元素都是可以遍历的. 如下例,list容器中存 ...