PAT甲级 1125. Chain the Ropes (25)
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:
8
10 15 12 3 4 13 1 15
Sample 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 long
const 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甲级——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甲题题解-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 (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[一般]
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 ...
- PAT 甲级 1044 Shopping in Mars (25 分)(滑动窗口,尺取法,也可二分)
1044 Shopping in Mars (25 分) Shopping in Mars is quite a different experience. The Mars people pay ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 【PAT甲级】1083 List Grades (25 分)
题意: 输入一个正整数N(<=101),接着输入N个学生的姓名,id和成绩.接着输入两个正整数X,Y(0<=X,Y<=100),逆序输出成绩在x,y之间的学生的姓名和id. tric ...
随机推荐
- Oracle_PL/SQL(10) 定时器job
定时器job1.定义 定时器指在特定的时间执行特定的操作. 可以多次执行.说明:特定的操作:指一个完成特定功能的存储过程.多次执行:指可以每分钟.每小时.每天.每周.每月.每季度.每年等周期性的运行. ...
- Loadrunner使用键盘快捷键
---------Loadrunner使用键盘快捷键------------ alt+f8 比较当前快照(仅限于 Web Vuser) alt+ins 新建步骤 ctrl+a 全选 ctrl+c 复制 ...
- 怎么隐藏服务器的IP地址?
服务器一般很少会使用公网地址,直接放置在互联网上使用. 一般是设置成局域网的私网地址,并通过路由器的端口映射,发布在互联网:内部的NAT转换,相当于隐藏了路由器,外网访问并不知道具体服务器的IP地址. ...
- Tinyos学习笔记(二)
1.TinyOS communication tools java serialApp -comm serial@/dev/ttyUSB0:telosb java net.tinyos.tools.L ...
- asio的网络通讯代码练手
asio的网络基本模板(单例模式 消息队列 ) // MyAsio.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include < ...
- .net判断当前时间是否在工作时间段内
整理代码,判断当前时间是否在配置的工作时间段内,代码如下: public static bool getTimeSpan(string _strWorkingDayAM, string _strWor ...
- 2016年3月31日_应化所群体Review
Review目的: Phonegap的ble插件可以接收到设备发送的信息,但接收并在控制台显示的数据夏一鸣不知道是正确的数据,还是由于编码解码问题导致的乱码问题.此次Review要解决的问题即判断接收 ...
- O365 Manager Plus详解
- ServiceDesk Plus更有序地组织IT项目
- kbmmw 5.05.00 发布
新年前最后几天,kbmmw 发布了新版本,增加一大波功能.we are happy to announce v5.05.50 of our popular middleware for Delphi ...