题目链接: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;
}

最新文章

  1. MySQL数据库实例参数对比脚本
  2. Js 的 this 是什么
  3. EGOImageView的使用方法及注意事项
  4. Oracle char 查询问题
  5. CSS3之背景色渐变
  6. JS判断页面加载是否完成
  7. Securing Spring Cloud Microservices With OAuth2
  8. asp.net core系列 26 EF模型配置(实体关系)
  9. Maven pom文件标签解析大全
  10. sql判断日期是否为当前季度
  11. ubuntu linux下建立stm32开发环境: 程序烧录 openocd+openjtag
  12. 构建高性能WEB站点之 吞吐率、吞吐量、TPS、性能测试
  13. Python Django orm操作数据库笔记之外键和表关系
  14. Hibernate 拦截器
  15. python的异常处理及异常类定义
  16. 【bzoj4520】 Cqoi2016—K远点对
  17. MySQL数据库如何去掉数据库中重复记录
  18. [C#]读文件
  19. vim常用快捷汇总
  20. 剑指Offer——和为S的两个数字

热门文章

  1. 工作2-5年,身为iOS开发的我应该怎么选择进修方向?
  2. sql 添加列并设置默认值
  3. avaScript中变量的声明和赋值
  4. Unity引擎GUI之Image
  5. SQL Server对数据进行删除
  6. 如何在编辑器打开Java程序
  7. AI:IPPR的数学表示-CNN基本结构分析( Conv层、Pooling层、FCN层/softmax层)
  8. PHP stream_socket_server
  9. Django--form组件cookie/session
  10. LINUX KERNEL SPINLOCK使用不当的后果