题目链接:http://acm.timus.ru/problem.aspx?

space=1&num=1826

1826. Minefield

Time limit: 0.5 second

Memory limit: 64 MB
To fulfill an assignment, a reconnaissance group of n people must cross the enemy's minefield. Since the group has only one mine detector, the following course of action is taken: two agents
cross the field to the enemy's side and then one agent brings the mine detector back to the remaining group. This is repeated until only two agents remain. These two agents then cross the field together.
Each person gets across the field at their own speed. The speed of a pair is determined by the speed of its slower member.
Find the minimal time the whole group needs to get over the minefield.

Input

The first line contains the integer n (2 ≤ n ≤ 100). The i-th of the following n lines specifies the time the i-th member of the group needs to get over
the minefield (the time is an integer from 1 to 600).

Output

Output the minimal total time the group needs to cross the minefield.

Sample

input output
4
1
10
5
2
17

题意:

有n个人要经过一片雷区,可是他们仅仅有一个扫雷用的探測器,所以每次仅仅能过去两个人,当中一个人把探測器拿回来,继续再过去两个人,

每一个人的行走速度不同,所花费的时间,是依照两个人中较慢的那个人所用时间计算的!

求所有人通过雷区的最短时间。

PS:

每次先把最大的两个移过去。当人数大于等于4的时候,

分两种情况:

1:最小的来回几次把最大的两个带过去。

2:先让最小的两个过去,然后最小的把探測器的回来,然后最大的两个过去,对面最小的把探測器带回来。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[147];
int ans = 0;
void cal(int m)
{
if(m == 1)
{
ans+=a[0];
}
else if(m == 2)
{
ans+=a[1];
}
else if(m == 3)
{
ans+=a[0]+a[1]+a[2];
}
else
{ if((a[0]*2+a[m-1]+a[m-2]) < (a[0]+2*a[1]+a[m-1]))
{
ans+=a[0]*2+a[m-1]+a[m-2];//0号一个人来回
}
else
{
ans+=a[0]+2*a[1]+a[m-1];//0,1号两个人来回
}
cal(m-2);
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
cal(n);
printf("%d\n",ans);
}
return 0;
}

URAL 1826. Minefield(数学 递归)的更多相关文章

  1. HDU 4472 Count(数学 递归)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 Problem Description Prof. Tigris is the head of ...

  2. CodeForces - 83D:Numbers (数学&递归 - min25筛 )

    pro:给定三个整数L,R,P求[L,R]区间的整数有多少个是以P为最小因子的.L,R,P<2e9; sol: 一: 比较快的做法是,用函数的思想递归. 用solve(N,P)表示求1到N有多少 ...

  3. POJ 1759 Garland(二分+数学递归+坑精度)

    POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...

  4. URAL1826. Minefield 题解

    原题: http://acm.timus.ru/problem.aspx?space=1&num=1826 1826. MinefieldTime limit: 0.5 secondMemor ...

  5. python专题 --- 递归

    如果一个函数在函数内部调用自身本身,这个函数就是递归函数 举例如阶乘函数,其数学递归定义如下: 对应的算法实现 def fact(n): if n==1: return 1 return n * fa ...

  6. 数据结构及算法分析(0)——引论

          引论提到算法递归的概念,递归在很多算法中都会出现.所谓递归,当一个函数用它自己来定义的时候就称为递归.     递归调用有两大要素: 基准情况. 递归调用.     并非所有的数学递归函数 ...

  7. 数据结构(c语言描述)

    预备的数学知识 数据结构的概念 基本名词 算法 线性表 线性表的定义和基本操作 顺序表 顺序表增 顺序表删 顺序表查 单链表 建立单链表 单链表增 单链表删 单链表查 双链表 循环链表 静态链表 栈 ...

  8. URAL 1876 Centipede's Morning(数学)

    A centipede has 40 left feet and 40 right feet. It keeps a left slippers and b right slippers under ...

  9. URAL 1820. Ural Steaks(数学啊 )

    题目链接:space=1&num=1820" target="_blank">http://acm.timus.ru/problem.aspx? space ...

随机推荐

  1. 模拟Queue(wait/notify)

    BlockingQueue:顾名思义,首先它是一个队列,并且支持阻塞的机制,阻塞的放入和得到数据.我们要实现LinkedBlockingQueue下面的两个方法put和take. put(anObje ...

  2. [转]逐步解說:在 WPF 應用程式中使用 ReportViewer 显示 rdlc

    本文转自:http://msdn.microsoft.com/zh-tw/library/hh273267 若要在 WPF 應用程式中使用 ReportViewer 控制項,您需要將 ReportVi ...

  3. Windows 环境下 Docker 使用及配置

    原文引用: https://www.cnblogs.com/moashen/p/8067612.html 我们可以使用以下两种方式在Windows环境下使用docker: 1. 直接安装: Docke ...

  4. C# 多线程系列(四)

    Parallel类 Parallel类定义了for.foreach和invoke的静态方法.Parallel类使用多个任务,因此使用多个线程来完成这个作业. Parallel.For Parallel ...

  5. CSS的常用属性(一)

    文本属性 font-size: 16px 文字大小 font-weight: 700 文字粗细 值从100-900 (值为700看上去加粗了) 不推荐使用font-weight: bold font- ...

  6. SQL Server 检测到基于一致性的逻辑 I/O 错误 pageid 不正确(应为 1:1772,但实际为 0:0)。在文件 'D:\Program Files\Microsoft SQL Ser

    SQL Server 检测到基于一致性的逻辑 I/O 错误 pageid 不正确(应为 1:1772,但实际为 0:0).在文件 'D:\Program Files\Microsoft SQL Ser ...

  7. ionic + cordova开发APP遇到的一些坑

    ionic1时期接触了这套体系,做了一个APP之后就放置了,最近又要开发一个APP,但时间不足以让我重头了解typescripts,于是又把之前做过的东西翻了出来,一边做一边掉坑里,爬上来再掉坑里,所 ...

  8. mysql手册操作

    1.show table status   显示表状态 2.VERSION()   版本:CURRENT_DATE   当前日期: NOW()   当前时间:USER   当前用户 3.GRANT A ...

  9. 使用JAVA写一个简单的日历

    JAVA写一个简单的日历import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateF ...

  10. Spring Cloud Alibaba、Spring Boot、Spring Cloud对应版本关系

    Spring Boot Spring Cloud Spring Cloud Alibaba 2.1.x Greenwich 0.9.x 2.0.x Finchley 0.2.x 1.5.x Edgwa ...