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). Then N positive integer lengths of the segments are given in the next line, separated by spaces. All the integers are no more than 1.

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
分析:因为所有⻓度都要串在⼀起,每次都等于(旧的绳⼦⻓度+新的绳⼦⻓度)/2,所以越是早加⼊绳
⼦⻓度中的段,越要对折的次数多,所以既然希望绳⼦⻓度是最⻓的,就必须让⻓的段对折次数尽可
能的短。所以将所有段从⼩到⼤排序,然后从头到尾从⼩到⼤分别将每⼀段依次加⼊结绳的绳⼦中,
最后得到的结果才会是最⻓的结果~
 #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n;
double res;
cin >> n;
vector<double>v(n);
for (int i = ; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = ; i < n; ++i)
v[i] = (v[i] + v[i - ]) / 2.0;
cout << floor(v[n - ]);//向下取整
return ;
}

PAT甲级——A1125 Chain the Ropes【25】的更多相关文章

  1. PAT甲级 1125. Chain the Ropes (25)

    1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  2. PAT甲题题解-1125. Chain the Ropes (25)-贪心水题

    贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...

  3. PAT 甲级 1044 Shopping in Mars (25 分)(滑动窗口,尺取法,也可二分)

    1044 Shopping in Mars (25 分)   Shopping in Mars is quite a different experience. The Mars people pay ...

  4. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  5. 【PAT甲级】1083 List Grades (25 分)

    题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...

  6. A1125. Chain the Ropes

    Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...

  7. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  8. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  9. PAT 甲级 1007 Maximum Subsequence Sum (25)(25 分)(0不是负数,水题)

    1007 Maximum Subsequence Sum (25)(25 分) Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A ...

随机推荐

  1. Vue.js 样式绑定(1)

    demo <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  2. python之next和send用法详解

    如果send不携带参数,那么send(None) 和next()的作用的相同的,如: def a(): print('aaa') p = ' #print(p) print('bbb') r = a( ...

  3. ajax--getJSON

    penson.json [ { "name":"张三", "age":25, "sex":"男", ...

  4. php基本,输出 ,变量

    <?php   //php开头//单行注释/*多行注释*/ echo "hello word";//输出 方式连续输出多个字符串print"hello word&q ...

  5. 27 和为S的两个数字

    0 引言 题目描述:输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 1 抽象问题具体化 举例: 序列为{1,2,3,4 ...

  6. CF 622F (拉格朗日插值)

    传送门 解题思路 比较经典的一道题目.第一种方法是差分,就是假设\(k=3\),我们打一个表. 0 1 9 36 100 225 1 8 27 64 125 7 19 37 61 12 18 24 6 ...

  7. NOIp2018集训test-9-18

    T1.Conjugate 只能选没选过的点,看成如果选了选过的堆的点就不管它继续选.如果第一次选到某一堆的点在第一次选到第一堆的点之前,这一堆对答案就会有1的贡献.那么a[i]有贡献的概率是a[i]和 ...

  8. (转) mysql的分区技术 .

    转:http://blog.csdn.net/feihong247/article/details/8100960 一.概述 当 MySQL的总记录数超过了100万后,会出现性能的大幅度下降吗?答案是 ...

  9. PaperWeekly 第五期------从Word2Vec到FastText

    PaperWeekly 第五期------从Word2Vec到FastText 张俊 10 个月前 引 Word2Vec从提出至今,已经成为了深度学习在自然语言处理中的基础部件,大大小小.形形色色的D ...

  10. Golang 交叉编译跨平台的可执行程序 (Mac、Linux、Windows )

    起因: 在项目中,我们每一次提交都需要添加commit 信息,而且我们的commit 信息,比较繁琐.我决定用golang语言编写一个小工具. 我决定使用语言:golang,使用工具:gox包. go ...