0
点赞
收藏
分享

微信扫一扫

A1125 Chain the Ropes (25 分| 排序| 贪⼼,附详细注释,逻辑分析)


写在前面

  • 思路分析
  • 越早加入段,对折次数越多。所以希望得到结绳最大长度,必须让长的段对折次数尽可能的少
  • 将所有段从小到大排序,从小到大分别将每段依次计入结绳
  • 打印最后结果
  • ​The result must be rounded to the nearest integer that is no greater than the maximum length.​
  • 英文单词

round :

  • 题目简单,5分钟a题

测试用例

input:
8
10 15 12 3 4 13 1 15

output:
14

ac代码

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<int> v(n);
for (int i = 0; i < n; i++)
scanf("%d", &v[i]);
sort(v.begin(), v.end(), less<int>());

double result = v[0];
for (int i = 1; i < n; i++)
result = (result + v[i]) / 2.0;
printf("%d", (int)result);
return 0;
}


举报

相关推荐

0 条评论