PAT 1125 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≤10^4 ). Then N positive 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
#include<iostream> //水题
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n, ans=0;
cin>>n;
vector<int> data(n, 0);
for(int i=0; i<n; i++)
cin>>data[i];
sort(data.begin(), data.end());
ans=data[0];
for(int i=1; i<n; i++)
ans=(ans+data[i])/2;
cout<<ans<<endl;
return 0;
}
PAT 1125 Chain the Ropes的更多相关文章
- 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 (25)
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 1125 Chain the Ropes (25 分)
1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- 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 ...
- 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甲级——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 ...
随机推荐
- 搜索goog
http://www.tech365.net/share/24.html 64.233.160.132|64.233.168.17|64.233.168.167|64.233.160.98|64.23 ...
- LVS集群体系和调度算法
集群体系和调度算法 LVS集群体系架构 1)使用LVS架设的服务器集群系统有三个部分组成: 最前端的负载均衡层,用Load Balancer表示, 中间的服务器群组层,用Server Array表示, ...
- java运行代码连接mysql时提示:找不到类错误
使用IntelliJ IDEA Community Edition进行代码编写.. 使用一下代码连接mysql时出现了:java.lang.ClassNotFoundException: com.my ...
- vue3.0新特性以及进阶路线
Vue3.0新特性/改动 新手学习路线 ===> 起步 1. 扎实的 JavaScript / HTML / CSS 基本功.这是前置条件. 2. 通读官方教程 (guide) 的基础篇.不要 ...
- event.target 属性返回哪个 DOM 元素触发了事件。
<ul> <li>list <strong>item 1</strong></li> <li><span>list ...
- Uva 796 Critical Links (割边+排序)
题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...
- BFS(最短路+路径打印) POJ 3984 迷宫问题
题目传送门 /* BFS:额,这题的数据范围太小了.但是重点是最短路的求法和输出路径的写法. dir数组记录是当前点的上一个点是从哪个方向过来的,搜索+,那么回溯- */ /************* ...
- [译]The multi Interface
The multi Interfacemulti接口 The easy interface as described in detail in this document is a synchrono ...
- 联想 Vibe Shot(Z90-7) 免recovery 获取ROOT权限 救砖 VIBEUI V3.1_1625
>>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...
- 5步上手体验kettle快捷调度方式
https://my.oschina.net/u/944575/blog/1557410 kettle调度监控最佳实践 https://my.oschina.net/u/1026947/blog/15 ...