题目:点击打开链接

思路:对于当前位置的每个时间段都要走一遍(除了那些须要的时间比最大同意的时间还大的),用 整形 vis[当前位置][剩余油量] 标记。

#include <cstdio>
#include <queue>
#include <algorithm>
#define INF 999999999
using namespace std; struct S{
int pos,time,remain; bool operator<(const S &p) const
{
return time>p.time;
} }t,oldt; int st[500][500][20],et[500][500][20],jt[500][500][20],head[500],nxt[2000],vis[500][2405],e[2000]; int main()
{
int n,m,i,j,a,b,u,v,time; while(scanf("%d%d",&n,&m) && n+m)
{
for(i=0;i<n;i++) head[i]=-1; for(i=0;i<m;i++)
{
scanf("%d%d",&a,&b); nxt[i*2]=head[a];
head[a]=i*2; nxt[i*2+1]=head[b];
head[b]=i*2+1; e[i*2]=b;
e[i*2+1]=a; for(j=0;;j++)
{
scanf("%d%d%d",&u,&v,&time); u*=10;
v*=10;
time*=10; st[a][b][j]=st[b][a][j]=u;
et[a][b][j]=et[b][a][j]=v;
jt[a][b][j]=jt[b][a][j]=time; if(v==14390) break;
}
} t.time=7200;
t.pos=0;
t.remain=2400; priority_queue<S>que; que.push(t); for(i=0;i<n;i++) for(j=0;j<2405;j++) vis[i][j]=INF; vis[0][t.remain]=t.time; while(!que.empty())
{
t=que.top(); if(t.pos==n-1)
{
printf("%d\n",(t.time-7200)/10); break;
} que.pop(); oldt=t; for(i=head[oldt.pos];i!=-1;i=nxt[i])
{
for(j=0;;j++)
{
if(jt[oldt.pos][e[i]][j]>2400)
{
if(et[oldt.pos][e[i]][j]<14390) continue;
else break;
} t.pos=e[i]; if(oldt.remain>=jt[oldt.pos][e[i]][j])//假设油足够
{
t.time=oldt.time;
t.remain=oldt.remain;
}
else//假设油不够,先加够再说
{
t.time=oldt.time+(jt[oldt.pos][e[i]][j]-oldt.remain)*2;
t.remain=jt[oldt.pos][e[i]][j];
} if(t.time%14400<st[oldt.pos][e[i]][j])
{
t.remain+=(st[oldt.pos][e[i]][j]-t.time%14400)/2;
if(t.remain>2400) t.remain=2400;
t.time+=st[oldt.pos][e[i]][j]-t.time%14400;
}
else if(t.time%14400>et[oldt.pos][e[i]][j])
{
t.remain+=(14400+st[oldt.pos][e[i]][j]-t.time%14400)/2;
if(t.remain>2400) t.remain=2400;
t.time+=14400+st[oldt.pos][e[i]][j]-t.time%14400;
} t.time+=jt[oldt.pos][e[i]][j];
t.remain-=jt[oldt.pos][e[i]][j]; if(t.time<vis[t.pos][t.remain])
{
que.push(t); vis[t.pos][t.remain]=t.time;
} if(et[oldt.pos][e[i]][j]==14390) break;
}
}
}
}
}

UVALive-6485-Electric Car Rally(BFS)的更多相关文章

  1. UVALive 6485 Electric Car Rally (BFS,PQ)

    https://icpcarchive.ecs.baylor.edu/index.php? option=com_onlinejudge&Itemid=8&page=show_prob ...

  2. UVALive 6665 Dragon’s Cruller --BFS,类八数码问题

    题意大概就是八数码问题,只不过把空格的移动方式改变了:空格能够向前或向后移动一格或三格(循环的). 分析:其实跟八数码问题差不多,用康托展开记录状态,bfs即可. 代码: #include <i ...

  3. UVALive 7297 Hounded by Indecision BFS

    题目链接:Hounded by Indecision 题意:map中给出小偷的位置,警察的位置.警察有一只狗,开始的时候警察和狗一起行动,也就是看做一个格子,当警察遇见小偷走过的格子时,狗就会嗅到它的 ...

  4. UVALive 3956 Key Task (bfs+状态压缩)

    Key Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/D Description The Czech Technica ...

  5. UVALive 2520 Holedox Moving(BFS+状态压缩)

    这个题目在比赛的时候我们是没有做出来的,但是听到他们说进制哈希的时候,感觉真的是挺高端的,于是赛后开始补题,本着我的习惯在看题解之前自己再试着写一遍,我当时存储状态的方法是string + map,我 ...

  6. UVALive 2035 The Monocycle(BFS状态处理+优先队列)

    这道题目真是非常坎坷啊,WA了很多次,但所有的思路都是奔着广搜去想的,一开始出现了比答案大的数据,才想到了应该是优先队列,再说加上也肯定不会错.一开始我读错了题意,以为旋转并且前行需要的时间跟其他一样 ...

  7. UVALive 6908 Electric Bike dp

    Electric Bike 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...

  8. What a Ridiculous Election UVALive - 7672 (BFS)

    题目链接: E - What a Ridiculous Election  UVALive - 7672 题目大意: 12345 可以经过若干次操作转换为其它五位数. 操作分三种,分别为: 操作1:交 ...

  9. UVALive 5066 Fire Drill BFS+背包

    H - Fire Drill Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

随机推荐

  1. 紫书 例题 10-24 UVa 1641(面积计算)

    遍历一遍,遇到边界为奇数次时,格子在多边形内 偶数次时,在多边形外 #include<cstdio> #define REP(i, a, b) for(int i = (a); i < ...

  2. Hdu 4930 斗地主

    模拟题,只是想纪念下,WA到死了…… 看到好多代码都好长,其实想说不用这么暴力. #include <iostream> #include <cstdio> #include ...

  3. 流水线技术原理和Verilog HDL实现

    所谓流水线处理,如同生产装配线一样,将操作执行工作量分成若干个时间上均衡的操作段,从流水线的起点连续地输入,流水线的各操作段以重叠方式执行.这使得操作执行速度只与流水线输入的速度有关,而与处理所需的时 ...

  4. EF数据迁移命令

    在包管理器控制台中输入命令“enable-migrations”,然后按Enter键!Visual Studio将生成一个名为“Configurations.cs”的文件; 你可以安全地忽略它,但你需 ...

  5. 关于Hive在主节点上与不在主节点上搭建的区别之谈

    Hive不在主节点上搭建,我这里是在HadoopSlave1上.

  6. Gallery滑动一页(一个Item)效果

    本文主要介绍如何使用Gallery只滑动一页以及其实现原理. Demo APK 可以方便的查看效果,在各大应用商店搜索 trinea android 下载即可,如:Google Play. 可运行代码 ...

  7. installp 软件的4种状态

    安装和维护LPP软件     installp 对包提供了如下四种主要的操作: Apply Commit Reject Remove   webes.4.0.0.1 commited webes.4. ...

  8. ubuntu server 网络配置,主机名配置

    一.通过命令ifconfig -a 查看可用网络设备 通过上面的命令,本机可用的网络设备为enp4s0f0 和enp4s0f1 ,不同的系统版本和硬件配置网络设备名可能不一样,所以一定要先确认本机可用 ...

  9. webpack+react实现echarts可视化配置

    先上效果 开发环境要求 需要事先安装node及npm 前期准备 1.创建文件夹react-echarts-editor2.在项目根目录(以下称根目录)下创建src目录3.在项目根目录下创建dist目录 ...

  10. 基于Pipe的PureMVC FLEX框架的多核共享消息技术

    pipes utilities,也就是所谓的通道(管道),为什么要使用通道呢?模块的结构都是一个单独的puremvc结构,模块和模块,shell和模块之间的通信 不能使用puremvc中的消息进行,因 ...