hdu1690 Bus System(最短路 Dijkstra)
The bus system of City X is quite strange. Unlike other city’s
system, the cost of ticket is calculated based on the distance between the two
stations. Here is a list which describes the relationship between the distance
and the cost.
Your
neighbor is a person who is a really miser. He asked you to help him to
calculate the minimum cost between the two stations he listed. Can you solve
this problem for him?
To simplify this problem, you can assume that all the
stations are located on a straight line. We use x-coordinates to describe the
stations’ positions.
single number above all, the number of cases. There are no more than 20
cases.
Each case contains eight integers on the first line, which are L1, L2,
L3, L4, C1, C2, C3, C4, each number is non-negative and not larger than
1,000,000,000. You can also assume that L1<=L2<=L3<=L4.
Two
integers, n and m, are given next, representing the number of the stations and
questions. Each of the next n lines contains one integer, representing the
x-coordinate of the ith station. Each of the next m lines contains two integers,
representing the start point and the destination.
In all of the questions,
the start point will be different from the destination.
For each
case,2<=N<=100,0<=M<=500, each x-coordinate is between
-1,000,000,000 and 1,000,000,000, and no two x-coordinates will have the same
value.
print the minimum cost between them. Otherwise, print “Station X and station Y
are not attainable.” Use the format in the sample.
const __int64 inf=0xffffffffffffff;
就过了,输入输出也要用__int64 !
#include <iostream>
#include <cstdio>
using namespace std;
const __int64 inf=0xffffffffffffff;
__int64 dist[],node[],vis[];
__int64 l[],c[],n; __int64 ab(__int64 a)
{
return a>?a:-a;
}
__int64 cost(__int64 dis)
{
if (dis>=&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
if (dis>l[]&&dis<=l[]) return c[];
} void Dijkstra(__int64 start,__int64 end)
{
for(int i=; i<=n; i++)
node[i]=inf,vis[i]=;
__int64 tm=start;
node[tm]=;
vis[tm]=;
for(int k=; k<=n; k++)
{
__int64 Min=inf;
for (int i=; i<=n; i++)
if(!vis[i]&&Min>node[i])
{
Min=node[i];
tm=i;
//cout<<" "<<tm<<" "<<Min<<endl;
}
if(tm==end)
{
printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",start,end,node[end]);
return ;
}
vis[tm]=;
for(int i=; i<=n; i++)
if(ab(dist[i]-dist[tm])<=l[]&&!vis[i]&&node[i]>node[tm]+cost(ab(dist[i]-dist[tm])))
{
//cout<<" "<<i<<" "<<node[tm]<<" "<<ab(dist[i]-dist[tm])<<" "<<hash[ab(dist[i]-dist[tm])]<<endl;
node[i]=node[tm]+cost(ab(dist[i]-dist[tm]));
}
}
printf ("Station %I64d and station %I64d are not attainable.\n",start,end);
} int main ()
{
int t,k=;
cin>>t;
while (t--)
{
//int l1,l2,l3,c1,c2,c3,c4;
cin>>l[]>>l[]>>l[]>>l[]>>c[]>>c[]>>c[]>>c[];
int m;
cin>>n>>m;
for(int i=; i<=n; i++)
cin>>dist[i];
printf ("Case %d:\n",k++);
while (m--)
{
int a,b;
cin>>a>>b;
Dijkstra(a,b);
}
}
}
hdu1690 Bus System(最短路 Dijkstra)的更多相关文章
- hdu1690 Bus System (dijkstra)
Problem Description Because of the huge population of China, public transportation is very important ...
- hdu 1690 Bus System(Dijkstra最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others ...
- hdu 2544 最短路 Dijkstra
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 题目分析:比较简单的最短路算法应用.题目告知起点与终点的位置,以及各路口之间路径到达所需的时间, ...
- 算法学习笔记(三) 最短路 Dijkstra 和 Floyd 算法
图论中一个经典问题就是求最短路.最为基础和最为经典的算法莫过于 Dijkstra 和 Floyd 算法,一个是贪心算法,一个是动态规划.这也是算法中的两大经典代表.用一个简单图在纸上一步一步演算,也是 ...
- HDU ACM 1690 Bus System (SPFA)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1690 Bus System (有点恶心)
Problem Description Because of the huge population of China, public transportation is very important ...
- 单源最短路dijkstra算法&&优化史
一下午都在学最短路dijkstra算法,总算是优化到了我能达到的水平的最快水准,然后列举一下我的优化历史,顺便总结总结 最朴素算法: 邻接矩阵存边+贪心||dp思想,几乎纯暴力,luoguTLE+ML ...
- hdu 1690 Bus System (最短路径)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HUD.2544 最短路 (Dijkstra)
HUD.2544 最短路 (Dijkstra) 题意分析 1表示起点,n表示起点(或者颠倒过来也可以) 建立无向图 从n或者1跑dij即可. 代码总览 #include <bits/stdc++ ...
随机推荐
- Pots(bfs)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8266 Accepted: 3507 Special Judge D ...
- COJ 2110 Day7-例3
Day7-例3 难度级别:C: 运行时间限制:5000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 输入 输入的第一行包含整数n和k,其中n(2 ≤ n ≤100 ...
- HDU 5396 Expression(DP+组合数)(详解)
题目大意: 给你一个n然后是n个数. 然后是n-1个操作符,操作符是插入在两个数字之间的. 由于你不同的运算顺序,会产生不同的结果. 比如: 1 + 1 * 2 有两种 (1+1)*2 或者 ...
- 行为树(Behavior Tree)实践(1)– 基本概念
原文地址:http://www.360doc.com/content/15/0107/11/15099545_438831036.shtml 自从开博以来,每天都会关心一下博客的访问情况,看到一些朋友 ...
- [JAVA关键字] static & final
JAVA十分常见的关键字static & final 总的来说final表示常量,即不可更改的:而static表示静态,即全局的 1. final 类:不能被继承 2. final 方法:能被 ...
- OpenStack 应用调试
- <一>初探js特效魅力之全选不选反选04
初探js特效魅力04 我们在进入到公司里面工作的时候,做一个同一个项目,经常是大家分工合作,当我们写css时,一般不写在行间,因为这样会被误操作,也就是被乱删了都不知道,这样的后果是很难检查的 ,因为 ...
- Java调用R(三)_系统命令调用
java通过配置的系统命令Rscript直接调用R脚本. 优点:R脚本和Java代码完全分离 缺点:R中变量不能控制 1. Java本地能够成功调用. public void CallR() { Ru ...
- PHP实现大文件的上传设置
打开php.ini,首先找到 ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; 区域,有影响文件上传的以下几个参数: file_uploads = ...
- 发起SSH攻击主机IP地址列表
发起SSH攻击主机IP地址列表 东北大学 http://antivirus.neu.edu.cn/scan/ssh.php 以下IP地址对SSH服务进行攻击,严重增加主机成为肉鸡的可能性.强烈建议网管 ...