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 ...
随机推荐
- bzoj3670 [Noi2014]动物园——KMP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3670 第一次写KMP算法...又T又WA了半天... 1. num 数组表示包括其本身的前缀 ...
- TI BLE STACK - OSAL
TI 的OSAL做的很不错,不过看起来也挺费劲可能自己水平太差吧,网上买的谷雨的开发板觉得确实挺不错的. 做点学习笔记,首先是记录OSAL里执行的顺序流程,主要是task ,event,message ...
- 【培训】MySQL
yum安装mysql:yum -y install mysql*- 或者 yum -y install mysql* 启动数据库服务:/etc/init.d/mysqld start 或者 servi ...
- Python基础 — Pandas
Pandas -- 简介 Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的. Pandas ...
- bzoj 1867: [Noi1999]钉子和小球【dp】
设f[i][j]为掉到f[i][j]时的概率然后分情况随便转移一下就好 主要是要手写分数比较麻烦 #include<iostream> #include<cstdio> usi ...
- Django day 33 vue中使用element-ui的使用,课程的相关介绍,vue绑定图片,课程列表接口,课程详情页面
一:vue中使用element-ui的使用, 二:课程的相关介绍, 三:vue绑定图片, 四:课程列表接口, 五:课程详情页面
- spring Cache /Redis 缓存 + Spring 的集成示例
spring Cache https://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ spring+redis 缓存 ht ...
- 微信公众号 sign类
微信公众号 Sign import java.util.UUID; import java.util.Map; import java.util.HashMap; import java.util.F ...
- DHTML_____如何编写事件处理程序
<html> <head> <meta charset="utf-8"> <title>如何编写事件处理程序</title&g ...
- 396 Rotate Function 旋转函数
给定一个长度为 n 的整数数组 A .假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的“旋转函数” F 为:F(k) = 0 * Bk[0] + 1 * Bk[1] + ... ...