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≤104). Then Npositive 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
分析:贪心题,自己做的时候直接排序然后从小开始两两对折最后输出结果就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 分)的更多相关文章
- PAT甲级 1125. Chain the Ropes (25)
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 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 ...
- 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
题意:略. 思路:思考一下,最先拿去对折的绳子会参与之后的每次对折,而对一条绳子而言,对折的次数越多剩下的就越短,因此,要让最终的结果尽可能长,应该先让较短的绳子先对折. 代码: #include & ...
- PAT1125:Chain the Ropes
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT_A1125#Chain the Ropes
Source: PAT A1125 Chain the Ropes (25 分) Description: Given some segments of rope, you are supposed ...
- 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 ...
随机推荐
- Apache Kafka 源码剖析
Getting Start 下载 http://kafka.apache.org/ 优点和应用场景 Kafka消息驱动,符合发布-订阅模式,优点和应用范围都共通 发布-订阅模式优点 解耦合 : 两个应 ...
- 【liunx】时间处理函数
一.脚本示例 [mylinuxaccount@linux01 ~]$ date +%Y%m%d 20171224 [mylinuxaccount@linux01 ~]$ date +%F 2017-1 ...
- 【mysql】索引原理-MySQL索引原理以及查询优化
转载:https://www.cnblogs.com/bypp/p/7755307.html 一.介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性 ...
- 每天进步一点点-写完睡觉-周一工作(java基本数据类型所占的字节和IO流读取的字符和字节)
- export的变量另开一个终端失效解决方法
有时候,我们需要把一个export的变量全局话,否则每开一个终端又需要重新export,很是麻烦 首先直接export某个变量的话就只能在当前子终端生效,另开一个终端就失效了 如果修改.bash_pr ...
- 文件访问控制列表facl
[root@bogon code]# getfacl a.c //获取文件a.c的文件访问控制列表 # file: a.c # owner: root # group: root user::rw- ...
- BINLOG和REDO/UNDO LOG的区别
BINLOG和REDO/UNDO LOG的区别1.处理层次不同,REDO/UNDO LOG由Innodb存储引擎处理,而BINLOG由MySQL 服务层处理.2.记录内容不同,REDO/UNDO LO ...
- Intellij IDEA2017.3永久激活方法
随着idea不断地发展,eclipse的缺点日渐明显,为了能够获得良好的编码体验,越来越多的朋友转向了idea,淘汰了eclipse但是由于近期idea所有私人服务器被封杀了,很多喜欢编码的朋友们都陷 ...
- buckaroo 去中心化的c++包管理工具
buckaroo 是一款去中心化的c++ 包管理工具,使用上,类似yarn(nodejs),cargo (rust) ,使用buckaroo 我们可以很容易集成一个大规模的项目 支持以下特性 直接从G ...
- IBM WebSphere MQ介绍安装以及配置服务详解
首先介绍一下MQ MQ消息队列的简称是一种应用程序对应用程序的通信方法.说白了也就是通过队列的方式来对应用程序进行数据通信.而无需专用链接来链接它们. MQ的通讯方式 1.数据报的方式 Datagra ...