UVa 1025 A Spy in the Metro
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913
预处理出每个时间、每个车站是否有火车
为了方便判断是否可行,倒推处理,每次有三种决策:原地坐等一分钟、搭车向左(如果有车)、搭车向右(如果有车)
/**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int mxn=;
int n,T;
bool h[mxn][mxn][];
int ti[mxn];
int m,d,e;
int f[mxn][mxn];
void clear(){
memset(ti,,sizeof(ti));
memset(h,,sizeof(h));
memset(f,,sizeof(f));
}
int main(){
int cnt=;
while(scanf("%d",&n) && n){
clear();
scanf("%d",&T);
int i,j;
for(i=;i<n;i++)scanf("%d",&ti[i]);//车站距离
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d",&d);//左边发车时间
for(j=;d<=T && j<=n;d+=ti[j],j++){
h[d][j][]=;
}
}
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d",&e);//右边发车时间
for(j=n;e<=T && j>=;j--,e+=ti[j]){
h[e][j][]=;
}
}
//以上全是初始化
f[T][n]=;
for(i=T-;i>=;i--){//倒推
for(j=;j<=n;j++){
f[i][j]=f[i+][j]+;//等待
if(j<n && h[i][j][] && i+ti[j]<=T)
f[i][j]=min(f[i][j],f[i+ti[j]][j+]);//向右
if(j> && h[i][j][] && i+ti[j-]<=T)
f[i][j]=min(f[i][j],f[i+ti[j-]][j-]);//向左
}
}
printf("Case Number %d: ",++cnt);
if(f[][]>=0xff) printf("impossible\n");
else printf("%d\n",f[][]);
}
return ;
}
UVa 1025 A Spy in the Metro的更多相关文章
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- UVA 1025 -- A Spy in the Metro (DP)
UVA 1025 -- A Spy in the Metro 题意: 一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, ...
- uva 1025 A Spy in the Metro 解题报告
A Spy in the Metro Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug Secr ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- UVA 1025 A Spy in the Metro 【DAG上DP/逆推/三维标记数组+二维状态数组】
Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After s ...
- uva 1025 A Spy int the Metro
https://vjudge.net/problem/UVA-1025 看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_< f[i][j]表示i时刻处于j站所需的最少等待时间,有 ...
- DAG的动态规划 (UVA 1025 A Spy in the Metro)
第一遍,刘汝佳提示+题解:回头再看!!! POINT: dp[time][sta]; 在time时刻在车站sta还需要最少等待多长时间: 终点的状态很确定必然是的 dp[T][N] = 0 ---即在 ...
- World Finals 2003 UVA - 1025 A Spy in the Metro(动态规划)
分析:时间是一个天然的序,这个题目中应该决策的只有时间和车站,使用dp[i][j]表示到达i时间,j车站在地上已经等待的最小时间,决策方式有三种,第一种:等待一秒钟转移到dp[i+1][j]的状态,代 ...
- UVa 1025 A Spy in the Metro (DP动态规划)
题意:一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
随机推荐
- java11-5 String类的转换功能
String的转换功能: byte[] getBytes():把字符串转换为字节数组. char[] toCharArray():把字符串转换为字符数组. static String valueOf( ...
- git review报错一例
在线上修改代码,最后使用git review提交代码审核的时候出现报错如下:[wangshibo@115~]$ vim testfile #修改代码[wangshibo@115~] ...
- java中的单引号和双引号
1.单引号引的数据 是char类型的,双引号引的数据 是String类型的:单引号只能引一个字符,而双引号可以引0个及其以上.char只是一个基本类型,而String 可以是一个类,可以直接引用.比如 ...
- UIVisualEffectView为视图添加特殊效果
在iOS 8后,苹果开放了不少创建特效的接口,其中就包括创建毛玻璃(blur)的接口. 通常要想创建一个特殊效果(如blur效果),可以创建一个UIVisualEffectView视图对象,这个对象提 ...
- 使用js使某个按钮在5秒内不能重复点击
<head> <!--参考:http://illy.iteye.com/blog/1534276 --> <!-- http://y.dobit.top/Detail/1 ...
- VBS操作Excel常见方法
VBS操作Excel常见方法 作者: 字体:[增加 减小] 类型:转载 时间:2009-11-13我要评论 VBS控制Excel常见方法,需要的朋友可以参考下. dim oExcel,oWb,oShe ...
- MyBatis出错Result Maps collection does not contain value for java.lang.Integer
Servlet.service() for servlet [SpringMVC] in context with path [/eyou] threw exception [Request proc ...
- [MySQL] 按日期进行统计(前一天、本周、某一天)
在mysql数据库中,常常会遇到统计当天的内容.例如,在user表中,日期字段为:log_time统计当天 sql语句为: select * from user where date(log_time ...
- [MetaHook] R_RicochetSprite
By hzqst void R_RicochetSprite(float *pos, model_t *pmodel, float duration, float scale) { TEMPENTIT ...
- 对于AP中为什么有4个WEP KEY的分析
这篇文章简要分析一下为什么有4个WEP KEY,及其中的一些原因. SPEC 用过AP的都知道,AP中有4个WEP KEY,但是为什么要设置4个呢,这个是WEP帧的格式决定的: 图中的keyid是2个 ...