博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL1826. Minefield 题解
阅读量:6894 次
发布时间:2019-06-27

本文共 2030 字,大约阅读时间需要 6 分钟。

原题:

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.

2~100个人要过雷区,只有一个探雷器,一次最多只能2个人过去,所以过去的流程是:过去2个回来一个过去2个回来一个…直到只剩2个的时候一起过去。2个一起走的时候以速度慢的人的速度为准。样例我看了好久没看懂,样例是4个人,单独过去的时间分别为1,2,5,10,先是1和2过去,1回来,5和10过去,2回来,1和2过去,一共2+1+10+2+2=17。

大致有两种策略,一种是最小的那个带大的过去,再回来带第二大的过去,再回来;另一种是最小的两个过去,最小的回来,然后最大的两个过去,第二小的回来。

好像可以贪心,这两种策略结束时都是最小的两个还在这边,最大的两个都去了那边,状态是一样的,所以这里选最优的策略就好。

不过我做的时候没想通,用了动规,i从大到小,dp[i][0]记录把i送过去时第二小的还在自己这边所耗的总时间,dp[i][1]记录把i送过去时第二小的在对面,所用的总时间。这样记录了第二小的位置,比较方便讨论几种送法。

动规代码如下:

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define MAXN 111 9 #define RE freopen("in.txt","r",stdin);10 #define inf 666666611 using namespace std;12 13 int n;14 int a[MAXN];15 int dp[MAXN][2];16 17 int farm();18 void init();19 20 int main()21 {22 //RE23 while(scanf("%d",&n)!=EOF)24 {25 farm();26 }27 return 0;28 }29 30 int farm()31 {32 int i,ans;33 for(i=0;i
1;i--)47 {48 dp[i][0]=dp[i+1][0]+a[i]+a[0];49 if(i
View Code

贪心的我没写…应该比这个简单。

转载于:https://www.cnblogs.com/yuiffy/p/3748128.html

你可能感兴趣的文章
ABP框架理论研究总结(典藏版)
查看>>
CNNVD发布2015年信息安全漏洞态势报告
查看>>
【深度】AI 入侵翻译,神经机器翻译进化让巴别塔7年内成真
查看>>
《Ext JS权威指南》——2.10节本章小结
查看>>
思科发布新系列智能协作终端产品
查看>>
脑芯编:窥脑究竟,织网造芯(一)
查看>>
《React Native移动开发实战》一一1.1 看透React Native
查看>>
大数据如何解决行业挑战?大数据在10个垂直行业中的应用
查看>>
分析师齐声唱多Facebook:发展势头凶猛 势不可挡
查看>>
Hadoop中ssh+IP、ssh+别名免秘钥登录配置
查看>>
安防设备需求爆发
查看>>
毫秒级大数据算法让生物识别取代密码
查看>>
找云合作伙伴 来云生态峰会
查看>>
八百客观点:如何让业务员对CRM爱不释手?
查看>>
泛微年报-OA行业第一家上市公司解读
查看>>
紫光集团已收购武汉新芯大多数股权
查看>>
恶意程序使用路由器 LED 灯从安全网络窃取数据
查看>>
智齿科技携手无忧我房 VR+AI新品亮相GTC
查看>>
中国已成全球七大重要出版市场之一 大数据提供新机遇
查看>>
法街头“种”下电子树 可提供WiFi、为手机充电
查看>>