题目链接

不知为何会在dp里呢。。。INF取小了,2Y。

 #include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define INF 1e9
int l1,l2,l3,c1,c2,c3;
int p[];
int dis[];
int in[];
int judge(int x,int y)
{
int d = p[x] - p[y];
if(d < )
d = -d;
if(d <= l1)
return c1;
if(d <= l2)
return c2;
if(d <= l3)
return c3;
return INF;
}
int main()
{
int i,n,sv,ev,w,u;
queue<int>que;
scanf("%d%d%d%d%d%d",&l1,&l2,&l3,&c1,&c2,&c3);
scanf("%d",&n);
scanf("%d%d",&sv,&ev);
for(i = ;i <= n;i ++)
scanf("%d",&p[i]);
for(i = ;i <= n;i ++)
{
dis[i] = INF;
in[i] = ;
}
dis[sv] = ;
in[sv] = ;
que.push(sv);
while(!que.empty())
{
u = que.front();
que.pop();
in[u] = ;
for(i = ;i <= n;i ++)
{
w = judge(i,u);
if(dis[i] > dis[u] + w)
{
dis[i] = dis[u] + w;
if(!in[i])
{
in[i] = ;
que.push(i);
}
}
}
}
printf("%d\n",dis[ev]);
return ;
}

URAL 1031. Railway Tickets(spfa)的更多相关文章

  1. 递推DP URAL 1031 Railway Tickets

    题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...

  2. POJ 2355 Railway tickets

    Railway tickets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2472   Accepted: 865 De ...

  3. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  4. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

  5. Ural 1036 Lucky Tickets

    Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...

  6. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  7. URAL(DP集)

    这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...

  8. POJ2828 Buy Tickets[树状数组第k小值 倒序]

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19012   Accepted: 9442 Desc ...

  9. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)

    题目链接: 传送门 Buy Tickets Time Limit: 4000MS     Memory Limit: 65536K Description Railway tickets were d ...

随机推荐

  1. 【mysql启动Innodb的方法】

    点击此处进入原网页 1.存储引擎是什么? Mysql中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力. ...

  2. 7z命令行工具

    7z (中文)是优秀开源的压缩解压缩软件(wiki: en  中文),有windows版本与linux版本,最新的9.32版本支持的格式包括: 压缩与解压缩均支持:7z, XZ, BZIP2, GZI ...

  3. 声明replicated属性之后我编译不通过的问题

  4. Git学习笔记 git revert

    我们难免会因为种种原因执行一些错误的commit / push,git提供了revert命令帮助程序员修复这样的错误. 举个例子,下图是git commit 的历史记录 git revert 命令会通 ...

  5. java.lang.UnsupportedClassVersionError: org/xwiki/xxx : Unsupported major.minor version 51.0

    此类问题主要是因为Unsupported major.minor version 51.0. 原因是JDK版本不一致导致的问题.在web应用中碰到此问题. 应用中规定使用JDK7.0,本地JDK为6. ...

  6. lvs+keepalived 负载均衡

    LVS是一个开源的软件,可以实现LINUX平台下的简单负载均衡.LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器.目前有三种IP负 载均衡技术(VS/NAT.VS/T ...

  7. Java Hour 67 Java Collection API

    本文不是一个大而全的讲述Java Coleection 相关的APi, 而是笔者认为哪些是一个初学者所能够而且必须确切知道的知识点. Collection 一脉 这里有我们比较常用的List<E ...

  8. bbed的使用--安装及初探

    bbed是oracle内部一款用来直接查看和修改数据文件数据的工具,可以直接修改Oracle数据文件块的内容,在一些特殊恢复场景下比较有用. 1.bbed 的安装 在9i/10g中连接生成bbed: ...

  9. tab_切换

    记忆: 一.这里用到了jQuery遍历---filter()方法: filter() 方法将匹配元素集合缩减为匹配指定选择器的元素. 二.HTML DOM hash属性 hash 属性是一个可读可写的 ...

  10. Struts2零配置介绍(约定访问)

    从struts2.1开始,struts2 引入了Convention插件来支持零配置,使用约定无需struts.xml或者Annotation配置 需要 如下四个JAR包 插件会自动搜索如下类 act ...