A1125. 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 <= 104). Then N positive 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
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
double rope[];
int N;
int main(){
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%lf", &rope[i]);
}
sort(rope, rope + N);
double ans = rope[];
for(int i = ; i < N; i++){
ans += rope[i];
ans = ans / 2.0;
}
int prt = ans;
printf("%d", prt);
cin >> N;
return ;
}
题意: 两段绳子可以合并成一段,但它们一合并,新绳子的长度就会变为原来两绳之长的和的一半,求能得到的最长的绳子。显然越早合并的绳子被1/2的次数就越多,所以要让越长的绳子尽量最后合并。
A1125. Chain the Ropes的更多相关文章
- 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 ...
- PAT_A1125#Chain the Ropes
Source: PAT A1125 Chain the Ropes (25 分) Description: Given some segments of rope, you are supposed ...
- 1125 Chain the Ropes (25 分)
1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...
- PAT1125:Chain the Ropes
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT甲级 1125. Chain the Ropes (25)
1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 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 (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 ...
随机推荐
- hive条件函数
case相当于if,when相当于=:then是条件满足的结论.否则实行else后语句,一end结束
- sonar结合jenkins
一.下载jenkins插件 二.系统设置 三.获取token值 4.调整 Jenkins 构建设置
- OSError: mysql_config not found
使用Python3开发一个管理平台,用MySQL数据库存放元数据.使用pip安装mysqlclient模块时出现“OSError: mysql_config not found”错误. 解决: # a ...
- debug方法
debug as -> spring boot->开始了 可以添加 ,, 来进行向下步骤:使用其他方法(在方法内打点) 一步步F6就可以了
- 四、Mysql主从同步
一.MySQL Replication介绍 MySQL Replication 官方文档 Replication可以实现将数据从一台数据库服务器(master)复制到一或多台数据库服务器(slave) ...
- spring boot和swagger 整合
本文来源:https://blog.csdn.net/saytime/article/details/74937664 一.依赖 <dependency> <groupId>i ...
- Lodop打印控件设置表格次页偏移
Lodop打印控件有很好的自动分页功能,超文本table表格一页装不下,自动分到第二页,第三页……通常表格之前还会有一些内容,比如标题,制表人名称日期什么的杂七杂八的东西,这种东西会占用一定的空间,这 ...
- WPF TextBox控件中文字实现垂直居中
TextBox纵向长度比较长但文字字体比较小的时候,在输入时就会发现文字不是垂直居中的. 而使用中我们发现,TextBox虽然可以设置文字的水平对齐方式,但却没有相应的属性让我们来调节他的垂直对齐方式 ...
- Spring Boot 构建电商基础秒杀项目 (五) 用户注册
SpringBoot构建电商基础秒杀项目 学习笔记 UserService 添加 void register(UserModel userModel) throws BusinessException ...
- mfs 使用心得
CentOS的安装方法: To install MooseFS from officially supported repository on EL7, follow the steps below: ...