PAT (Basic Level) Practise (中文)1070. 结绳(25)
来源:互联网 发布:自考网络助学加分 编辑:程序博客网 时间:2024/06/02 03:24
1070. 结绳(25)
时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
给定一段一段的绳子,你需要把它们串成一条绳。每次串连的时候,是把两段绳子对折,再如下图所示套接在一起。这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连。每次串连后,原来两段绳子的长度就会减半。
给定N段绳子的长度,你需要找出它们能串成的绳子的最大长度。
输入格式:
每个输入包含1个测试用例。每个测试用例第1行给出正整数N (2 <= N <= 104);第2行给出N个正整数,即原始绳段的长度,数字间以空格分隔。所有整数都不超过104。
输出格式:
在一行中输出能够串成的绳子的最大长度。结果向下取整,即取为不超过最大长度的最近整数。
输入样例:810 15 12 3 4 13 1 15输出样例:
14
#include <cstdio>#include <algorithm>using namespace std;const int maxn=10000+10;int a[maxn];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int ans=a[0]; for(int i=1;i<n;i++) ans=(ans+a[i])/2; printf("%d\n",ans); return 0;}
阅读全文
0 0
- PAT (Basic Level) Practise (中文) 1070. 结绳(25)
- PAT (Basic Level) Practise (中文)1070. 结绳(25)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1015. 德才论 (25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT (Basic Level) Practise (中文)1030. 完美数列(25)
- PAT (Basic Level) Practise (中文)1050. 螺旋矩阵(25)
- PAT (Basic Level) Practise (中文)1045快速排序(25)
- PAT (Basic Level) Practise (中文)1020月饼 (25)
- TensorFlow实战3:实现Logistic回归小例子
- List的toArray方法强制转换
- Unable to merge dex,专治Android Studio各种抽风!
- 数据库事务的四大特性
- android studio中取消关联git
- PAT (Basic Level) Practise (中文)1070. 结绳(25)
- 编写高效代码(1) 减少函数调用——不要老打断我
- C语言初始化的基础问题
- Tensorflow模型持久化的代码实现
- 注册码激活
- android笔记 中TextView修改部分字体颜色或样式
- 概率分布之间的距离度量以及python实现
- 转转&去哪儿 技术沙龙
- java23种设计模式之单例模式