PAT甲级 1125. Chain the Ropes (25)
来源:互联网 发布:zencart建站 编辑:程序博客网 时间:2024/05/19 17:52
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 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:810 15 12 3 4 13 1 15Sample Output:
14
————————————————————————————————
题目的意思是将n个绳子两两合并,每次长度变为和的一半,问最后变成1根的长度最大是多少
思路,每次合并每一根绳子会变为原来的1/2,所以最长的肯定合的越少越好,贪心妹子选择最短的合并
include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<string>#include<queue>#include<stack>#include<map>#include<set>using namespace std;#define LL long longconst int inf=0x3f3f3f3f;int main(){ int n; int a[100005]; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); for(int i=1;i<n;i++) { a[i]=(a[i]+a[i-1])/2; } printf("%d\n",a[n-1]); return 0;}
- PAT 1125. Chain the Ropes (25)-甲级
- PAT甲级.1125. Chain the Ropes (25)
- PAT甲级 1125. Chain the Ropes (25)
- PAT 甲级 1125. Chain the Ropes (25)
- 1125. Chain the Ropes (25) PAT 甲级&&1070. 结绳(25) PAT 乙级
- PAT 1125. Chain the Ropes (25)
- PAT--1125. Chain the Ropes
- 2017.3.4 pat甲级B题Chain the Ropes
- PAT (Advanced Level) 1125. Chain the Ropes (25)
- PAT (Advanced Level) 1125. Chain the Ropes (25) 解题报告
- 【PAT】【Advanced Level】1125. Chain the Ropes (25)
- pat 甲1125. Chain the Ropes (贪心)
- PAT A1125. Chain the Ropes (25)(哈夫曼树)
- 1125. Chain the Ropes (25)
- 1125. Chain the Ropes (25)
- 1125. Chain the Ropes (25)
- 1125. Chain the Ropes (25)
- 1125. Chain the Ropes (25)
- [笔记]linux内存管理机制
- (OK) Android-x86-7.1.1/ kernel 4.4.62
- 移动游戏IP在出海是否依然有效
- 查看Redis版本信息
- https站点强制通信协议TLSv1.2
- PAT甲级 1125. Chain the Ropes (25)
- vue 笔记(正在补充中。。。)
- 微信小程序开发入门篇 30分钟内教你写出一个helloword小程序
- 比较推荐学习Linux系统应该看的书籍
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party
- *p++ 和 (*p)++
- 机器翻译之Facebook的CNN与Google的Attention
- SpringMVC集成Hibernate的主要配置
- Java读取文件创建时间和最后修改时间