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 ...
随机推荐
- bzoj2705 [SDOI2012]Longge的问题——因数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705 一开始自己想了半天... 有了点思路:遍历 n 的因数 k,每个因数要预处理出 gcd ...
- IJ:Eclipse快捷键大全
ylbtech-IJ:Eclipse快捷键大全 1.返回顶部 1. Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加 ...
- C#面向过程之冒泡排序
//定义一个数组,准备冒泡排序 ,,-,,,,-,}; //定义一个中间变量 ; //n个数字比较需要进行n-1次比较 ; j < arr.Length - - i; j++) { //每一趟的 ...
- vue 加载文件,省略后缀后的加载顺序
Vue使用import ... from ...来导入组件,库,变量等.而from后的来源可以是js,vue,json.这个是在webpack.base.conf.js中设置的: module.exp ...
- AutoCAD C# 利用反射导出所注册的命令
主函数导出某一程序集AutoCAD 注册命令 /// <summary> ///提取所有的命令 /// </summary> /// <param name=" ...
- Odoo免费开源企业信息化平台助力企业成功
企业信息化变革之路 信息孤岛的真实由来 打开百度App,看更多图片 左边为当下企业现状,右边为Odoo的整体 企业信息孤岛的严重性,来自于企业的自身高速发展,企业以销售为生命主题围绕着客户会搭建一系列 ...
- 【css】回想下经典的布局
看到这张图相信大多数人都很熟悉,这曾经是一种经典的布局方式,一道经典的面试题,一般形如"实现一个布局,左右固定宽度,中间自适应".随着岁月的流转,时光的交替(颇有一种“天下风云出我 ...
- Linux环境下修改MySQL数据库存储引擎
今天在执行Oracle数据库迁移至MySQL数据库时报出了一个错误信息: Specified key was too bytes 百度发现,原来需要更改MySQL数据库的存储引擎为InnoDB,查询目 ...
- [转].net cookie版购物车
本文转自:http://www.sulong.cc/article/program/aspx/110613114249.html #region 添加到购物车AddShoppingCar /// &l ...
- [ Nowcoder Contest 175 #B ] 区间
\(\\\) \(Description\) 给出一个长度为\(N\)的序列\(A[1]...A[N]\),定义一个合法区间 \([L,R]\) 当且仅当区间\(GCD\) 在这个区间内,求最长合法区 ...