http://acm.nyist.net/JudgeOnline/problem.php?pid=47

http://poj.org/problem?id=1700

解题思路:求最少需要多少时间才能都通过。先将每个人过河所需的时间升序排序

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 int a[];
 6 int n, t, i;
 7 int ans;
 8 
 9 int cmp(const void *a, const void *b){
     return *(int *)a - *(int *)b;
 }
 
 void solve(){
     ans = ;
     while(n){
         if(n == ){
             ans += a[];
             break;
         }
         else if(n == ){
             ans += a[];
             break;
         }
         else if(n == ){
             ans += a[] + a[] + a[];
             break;
         }
         else{
             //人较多的情况下,判断是先把走得最慢的两个人送过去合算还是先把走得最快和最慢的人先送过去
             if( * a[] > a[] + a[n - ]){
                 ans += (a[n - ] + a[n] +  * a[]);
             }
             else{
                 ans += (a[] +  * a[] + a[n]);
             }
             n -= ;
         }
     }
     printf("%d\n", ans);
 }
 
 int main(){
     scanf("%d", &t);
     while(t--){
         scanf("%d" ,&n);
         for(i = ; i <= n; i++){
             scanf("%d", &a[i]);
         }
         qsort(a + , n, sizeof(a[]), cmp);
         solve();
     }
     return ;

53 }

nyoj-47-过河问题|POJ-1700-Crossing River的更多相关文章

  1. poj 1700 Crossing River 过河问题。贪心

    Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9887   Accepted: 3737 De ...

  2. POJ 1700 Crossing River (贪心)

    Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...

  3. poj 1700 Crossing River C++/Java

    http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最 ...

  4. POJ 1700 - Crossing River

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13982   Accepted: 5349 Description A gr ...

  5. 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 ca ...

  6. POJ 1700 cross river (数学模拟)

                                                                                                       ...

  7. 1700 Crossing River

    题目链接: http://poj.org/problem?id=1700 1. 当1个人时: 直接过河 t[0]. 2. 当2个人时: 时间为较慢的那个 t[1]. 3. 当3个人时: 时间为 t[0 ...

  8. nyoj 47——过河问题——————【贪心】

    过河问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边.如果不借助手电筒的话,大家是无论如何也不敢过桥去的 ...

  9. NYOJ 47过河问题

    主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...

  10. Crossing River(1700poj)

    Crossing River Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9919   Accepted: 3752 De ...

随机推荐

  1. 线程通讯-Condition

    Account类 package com.thread.communication.condition; import java.util.concurrent.TimeUnit; import ja ...

  2. iOS代码封装成.a文件(封装SDK)

    在众多开源的大神的博客里经整理如下:(已测试ok) 一.描述一下 Build ActiveArchitecture Only设置成YES: Architectures按Xcode默认配置,arm64向 ...

  3. Unity2d 骨骼动画3:介绍Mecanim和脚本

    http://bbs.9ria.com/thread-402710-1-1.html 在这个系列,我们将关注Unity引擎提供的基于骨骼动画工具.它的主要思想是为了把它应用到你自己的游戏来介绍和教基本 ...

  4. Matplotlib 如何显示中文

    Python 3.x 主要是如下代码 import os font = FontProperties(fname=os.path.expandvars(r"%windir%\fonts\si ...

  5. [HNOI2010] 弹飞绵羊 bounce

    标签:分块.题解: 200000,而且标号从0开始,很符合分块的条件啊.看看怎么实现. 首先分成√n个区间,然后如果我们对于每一个位置i,求出一个Next[i]和step[i],分别表示跳到的后一个位 ...

  6. 给 UILabel 中的文字增加 line-through / Strikethrough (删除线)样式

    iOS 6 中苹果引入了 NSStrikethroughStyleAttributeName 属性,用于设置 NSAttributedString 的删除线样式,用法如下: let attribute ...

  7. 编译出现No rule to make target `out/host/linux-x86/bin/aapt', needed by `out/target/common/obj/APPS/MyTv4_intermediates/src/R.stamp'问题

    查找路径发现的确没有MyTv4_intermediates/src/R.stamp,这需要生成这个文件

  8. C - Catch That Cow POJ - 3278

    //标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...

  9. Codeforces 997D(STL+排序)

    D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...

  10. CentOS Linux 搭建 SVN(CollabNet Subversion)服务器

    安装CollabNet Subversion之前必须先安装JDK1.6和python2.4 ~ 2.6 groupadd svn useradd -g svn svnuser  passwd svnu ...