题目链接: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. RecastNavigation(3D场景建模、网格导航)

    一.RecastNavigation详解 RecastNavigation定义: RecastNavigation是一个导航寻路工具集,使用邻接的凸多边形集合描述一个3D场景,A*寻路算法使3D场景的 ...

  2. jquery.validate验证text,checkbox,radio,selected

    index.cshtml <form id="formLogin" method="post"> <div> <label for ...

  3. 省市区县的sql语句——区县

    DROP TABLE IF EXISTS `area`; CREATE TABLE `area` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `code` va ...

  4. AO如何获取SDE数据库中的数据

    /// <summary> /// 获取Table类型表的记录 /// </summary> /// <param name="relationCheckCla ...

  5. hibernate_07_单表操作_增删改操作

    首先,创建类对象 package com.imooc.hibernate; public class Address { private String postcode; //邮编 private S ...

  6. GraphicsMagick在centos环境的安装

    一.需要安装包libpng-1.6.2rc02.tar.gz,libjpeg-6b.tar.gz,GraphicsMagick-1.3.18.tar.gz,GraphicsMagick-1.3.18最 ...

  7. Delphi 不用标题栏移动窗体

    procedure TxxxxForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: I ...

  8. efcore 控制台迁移架构

    添加 nuget 包: Microsoft.EntityFrameworkCore.Design Microsoft.EntityFrameworkCore.SqlServer Microsoft.E ...

  9. linux系统下安装memcached

    检查libevent 首先检查系统中是否安装了libevent rpm -qa|grep libevent 如果安装了则查看libevent的安装路径,后续安装时需要用到 rpm -ql libeve ...

  10. Day 19 numpy 模块

    numpy 模块(多维数组) import numpy as np arr=np.array([1,2,3,4],[5,6,7,8]) print(arr) #[[1 2 3 4] #[5 6 7 8 ...