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 ...
随机推荐
- FitLayout
<HTML> <HEAD> <TITLE>布局</TITLE> <link rel="stylesheet" type=&qu ...
- [Android UI] ActionBar 自定义属性
actionbar 默认放在顶部, 如果在application或者activity中加入 android:uiOptions="splitActionBarWhenNarrow" ...
- 【屌丝程序的口才逆袭演讲稿50篇】第十三篇:爱迪生欺骗了我们!【张振华.Jack】
演讲稿主题:<爱迪生欺骗了我们> --作者:张振华Jack.摘抄<马云为雅虎员工的演讲稿:爱迪生欺骗了我们> 非常多人都记得爱迪生说的 ...
- iOS:制作九宫格
制作简单的九宫格: 源码如下: #import "ViewController.h" @interface ViewController () @end @implementati ...
- 同步FIFO的设计
module scfifo #( , ) ( input clk, input rst_n, input wren, input rden, :] din, :] dout, output full, ...
- TCP三次握手四次挥手相关问题探讨
TCP的握手挥手和状态转换是很多网络问题的基础.在此进行相关问题的讨论及记录. 首先,这幅图大致介绍了TCP连接和断开的过程: 注意其中的几个状态: LISTEN, SYN-SEND, SYN-RCV ...
- Word Break leetcode java
题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...
- 实现iframe窗口高度自适应的又一个巧妙思路
domainA 中有一个页面index.html,通过iframe嵌套了domainB中的一个页面other.html由于other.html页面在iframe中显示,而且其页面内容会动态的增加或减少 ...
- Android之批量加载图片OOM问题解决方案
一.OOM问题出现的场景和原因 一个好的app总少不了精美的图片,所以Android开发中图片的加载总是避免不了的,而在加载图片过程中,如果处理不当则会出现OOM的问题.那么如何彻底解决这个问题呢?本 ...
- 锐浪报表 导出 PDF ANSI码 乱码 问题解决
锐浪 报表 导出PDF时如果 ANSI 码 打勾了会乱码,能将这个选项默认不打勾吗 //在报表导出事件脚本里写脚本,可实现导出控制Sender.AsE2PDFOption.AnsiTextMode=0 ...