hdu1690Bus System--解题报告
题意:有一个公交系统的收费标准例如以下表:
<span style="font-size:14px;">#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring> using namespace std; #define INF 0xffffffffffffff
#define MAX 105
#define LL __int64 int N,M;
LL L1,L2,L3,L4,C1,C2,C3,C4;
LL X[MAX]; struct Edge{
int to,next;
LL cost;
}edge[MAX*MAX];
int head[MAX],tol; void add(int u,int v,LL cost)
{
edge[tol].to = v;
edge[tol].cost = cost;
edge[tol].next = head[u];
head[u] = tol++;
} void del() //处理建边
{
LL cost,dis;
for(int i = 1; i <= N; i ++){
for(int j = i+1; j <= N; j ++){
if(X[i] > X[j]) dis = X[i]-X[j];
else dis = X[j]-X[i]; if(dis > L4) cost = INF;
else if(dis > L3) cost = C4;
else if(dis > L2) cost = C3;
else if(dis > L1) cost = C2;
else cost = C1; add(i,j,cost);
add(j,i,cost);
}
}
} LL dis[MAX];
bool flag[MAX];
LL spfa(int src,int D)
{
for(int i = 1; i <= N; i ++) dis[i] = INF;
memset(flag,false,sizeof(flag));
dis[src] = 0;
flag[src] = true; queue<int>q;
q.push(src); while(!q.empty())
{
int u = q.front(); q.pop();
flag[u] = false;
for(int i = head[u]; i != -1; i = edge[i].next)
{
int v = edge[i].to; LL cost = edge[i].cost;
if(cost + dis[u] < dis[v])
{
dis[v] = cost+dis[u];
if(!flag[v])
{
q.push(v);
flag[v] = true;
}
}
}
}
return dis[D];
} int main()
{
int T;
scanf("%d",&T); for(int cas = 1; cas <= T; cas ++)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&L1,&L2,&L3,&L4,&C1,&C2,&C3,&C4);
scanf("%d%d",&N,&M);
for(int i = 1; i <= N; i ++) scanf("%I64d",&X[i]); memset(head,-1,sizeof(head));
tol = 0; del(); printf("Case %d:\n",cas);
int a,b;
LL ans = 0;
for(int i = 0; i < M; i ++)
{
scanf("%d%d",&a,&b);
ans = spfa(a,b);
if(ans >= INF)
printf("Station %d and station %d are not attainable.\n",a,b);
else
printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,ans);
}
} return 0;
}</span>
那么这里的话,还要注意的是 由于坐标值比較大,我们用 64位来保存
hdu1690Bus System--解题报告的更多相关文章
- 【LeetCode】1166. Design File System 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 目录树 日期 题目地址https://leetc ...
- 【LeetCode】609. Find Duplicate File in System 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...
- 北邮新生排位赛1解题报告d-e
话说cdsn要是前面插入源代码又什么都不放就会出现奇怪的源代码?不知道是哪个网页的 407. BLOCKS 时间限制 1000 ms 内存限制 65536 KB 题目描述 给定一个N∗M的矩阵,求问里 ...
- C-C Radar Installation 解题报告
C-C Radar Installation 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...
- ZOJ_3950_How Many Nines 解题报告及如何对程序进行测试修改
The 17th Zhejiang University Programming Contest Sponsored by TuSimple Solution: #include <stdio. ...
- LeetCode: Permutations 解题报告
Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] ha ...
- ACM-ICPC 2017 Asia HongKong 解题报告
ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- 【九度OJ】题目1040:Prime Number 解题报告
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...
随机推荐
- java中方法drawImage()的参数详细解释
public abstract boolean drawImage(Image img,int x,int y,int width,int height,ImageObserver observer) ...
- 如何判断某版本的.NET Framework是否安装
1..NET Framework .NET Framework2.0 键:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\N ...
- php的初步了解
刚刚学习PHP,在学校中没有接触过这个语言,但是身边的人都说php好,经过这几天的学习,我对它的基础有了一定的认知和了解,php是“PHP Hypertext Preprocessor”的首字母缩写, ...
- Gedit
Use Gedit as Remote File Editor via FTP and SSH Migrating from Windows Vista to Ubuntu 8.04 and have ...
- poj 1469 COURSES 题解
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21515 Accepted: 8455 Descript ...
- iOS开发-NSPredicate
Cocoa中谓词(Predicate)提供了一个通用的查询方式处理数据,可以获取和指定数据的过滤形式,Cocoa实际开发中可以是使用NSPredicate及其父类NSComparisonPredica ...
- myeclipse创建maven android项目
一.搭建环境 1.安装android maven插件,我在网上找了半天.没有找到这个插件,于是选择了在线安装.选择myeclipse 的 [help]->[install form catalo ...
- ListBoxEdit
<dxe:ListBoxEdit ShowBorder="False" SelectedIndex="0" x:Name="lbView&quo ...
- Cognos 报表在列表上面显示汇总
一直以来,Cognos Report Studio设计报表的时候,汇总默认显示在列表下方: 1如图,拖一个列表 2运行如下,数据显示正常按日期排序 3选中订单笔数.订单金额,添加自动汇总 4:运行,可 ...
- (转)[Unity3D]UI方案及制作细节(NGUI/EZGUI/原生UI系统) 内附unused-assets清除实例
转载请留下本文原始链接,谢谢.本文会不定期更新维护,最近更新于2013.09.17. http://blog.sina.com.cn/s/blog_5b6cb9500101bplv.html ...