poj 1700 Crossing River(贪心)

分析:题意

源岸数量<=3  很好判断 3:num[0]+num[1]+num[2] 2:num[1] ,1:num[0]

源岸数量>3

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
    int n,t ;
    int i,j;
    int num[1001];
    cin>>t;
    while(t--){
        cin>>n;
        for(i=0;i<n;i++) cin>>num[i];
        sort(num,num+n);
        int cnt=n,sum=0;
        while(cnt>3){
            int w1=num[0]+2*num[1]+num[cnt-1],w2=2*num[0]+num[cnt-2]+num[cnt-1];
            sum+=min(w1,w2);
            cnt-=2;
        }
        if(cnt==3) sum+=num[0]+num[1]+num[2];
        else if(cnt==2) sum+=num[1];
        else sum+=num[0];
        cout<<sum<<endl;
    }
    return 0;
}
时间: 2024-08-06 07:55:47

poj 1700 Crossing River(贪心)的相关文章

POJ 1700 Crossing River(贪心)

V - Crossing River Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1700 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. There

[ACM] poj 1700 Crossing River (经典过河问题)

Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10212   Accepted: 3855 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arr

poj 1700 Crossing River

Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12585   Accepted: 4787 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arr

ACM学习历程——POJ 1700 Crossing River(贪心)

Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must be arranged in order to row the boat back and forth so that all people may cross. Eac

poj 1700 Crossing River C++/Java

http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最短时间. 思路: 贪心. 对于每次过河的,有两种情况: //最快和最慢过去,然后最快回来.在和次慢过去.最快回来 int action1=a[i-1] + a[0] + a[i-2] +a[0]; //最快和次慢过去,然后最快回来,在次慢和最慢过去,次慢回来 int action2=a[1] +a[

POJ 1700 cross river (数学模拟)

 Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10311   Accepted: 3889 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle

1700 Crossing River

题目链接: http://poj.org/problem?id=1700 1. 当1个人时: 直接过河 t[0]. 2. 当2个人时: 时间为较慢的那个 t[1]. 3. 当3个人时: 时间为 t[0]+t[1]+t[2]. 4. 当4个以上的人时, 将t[0] 和 t[1]当作搬运工. 两种方案: - 最快和次快的过去, 最快的回来, 最慢和次慢的过去, 次快的回来, 这样就将最慢和次慢的送过去了. 时间: t[0]+2*t[1]+t[i] - 最快的依次送最慢和次慢的过去再回来, 时间: 2

POJ1700 Crossing River(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 13301          Accepted: 5087 Description A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shu

【POJ1700】Crossing River 贪心,附贪心问题的一系列详细解析

题意:一群人过河,船每次只能装两人,每次过河时间为两人权值较大的那个. 题解: 这种题的贪心策略往往不是很好想,这个时候我们就需要依照尽量逼近正解的思路,进行多种贪心,在每种贪心都保证正确的前提下,取多个答案的最值,这样往往就是正解,而即便可以卡,数据也很难出,并不是写个rand+debug拍上两个小时就能拍出来的. 而这种 多线程贪心 可以有两种: 一.单独做每种,然后取最优. 二.每一步转移都用多种贪心取得,然后直接取最后的状态值. 显然后一种的正确性比较高,但是往往因为"贪心"的