首页 > 其他 > 详细

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

时间:2017-03-05 20:41:41      阅读:223      评论:0      收藏:0      [点我收藏+]

贪心水题,每次取最短的两个绳子合并,长度缩减成一半

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
using namespace std;
const int maxn=10000+5;
int a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    float lastlen=a[0];
    for(int i=1;i<n;i++){
        lastlen=(lastlen+a[i])/2;
    }
    printf("%d\n",(int)lastlen);
    return 0;
}
View Code

 

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

原文:http://www.cnblogs.com/chenxiwenruo/p/6506444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!