浙江科技学院第十三届程序设计竞赛 1008 A Heavy Rainy Day 贪心

思路:可以分以最快和最慢的四个人为一组,或者最快的一个人和最慢的俩个人一组,比较用时最少的即可。

图中为数组下标

#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
#include<stack>
#include<iostream>
#include<cstring>
#include<algorithm>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define mod 1000000007
#define ls l,mid,rt<<1
#define rs mid+1,rt,rt<<1|1
#define LL __int64
using namespace std;
int nu[1010];

int main(){
    int n,m,i,j,k,cla;
    while(~scanf("%d",&n)){
        for(i = 0;i < n;++ i){
            scanf("%d",&nu[i]);
        }
        int ans = 0;
        sort(nu,nu + n);
        while(n >= 4){
            if(2*nu[0]+nu[n-2]+nu[n-1] > 2*nu[1]+nu[0]+nu[n-1])
                ans += 2*nu[1]+nu[0]+nu[n-1];
            else
                ans += 2*nu[0]+nu[n-2]+nu[n-1];
            n -= 2;
        }
        if(n == 3)
            ans += nu[0]+nu[1]+nu[2];
        else if(n == 2)
            ans += nu[1];
        else
            ans += nu[0];
        printf("%d\n",ans);
    }
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值