UVA 1518 Train delays
比较简单的一道题目,考察逆推法,从终点逆推到起始点即可,注意要存储每条边的信息,对应的每个顶点要考虑所有的发车时间以及利用概率计算相应的期望值即可,具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
const int N = 2100;
const double Inf = 10000000000000.00;
const double ex = 1e-10;
double cost[N][60];
vector<double> test;
class Road{
public:int from, to, start, dur, per, delay;
};class Solve{
public:map<string, int> record;int amount;string starts, ends;int total;vector<int> G[N];vector<Road> road;bool visit[N];int s_ind, e_ind;int find_location(string s){if (record.find(s) != record.end()) return record[s];record[s] = amount;return amount++;}bool update(int ide){bool flag = false;int from = road[ide].from;int to = road[ide].to;for (int i = 0; i < 60; i++){double wait = (road[ide].start - i + 60) % 60;double total_cost = (1.0 - road[ide].per / 100.0)*(road[ide].dur+cost[to][(road[ide].start+road[ide].dur)%60]);for (int j = 1; j <= road[ide].delay; j++)total_cost += 1.0*road[ide].per / 100.0 / road[ide].delay*(road[ide].dur + j+cost[to][(road[ide].start+j+road[ide].dur)%60]);if (total_cost+wait < cost[from][i]-ex){cost[from][i] = total_cost+wait;flag = true;}}return flag;}void getRes(){queue<int> q;q.push(e_ind);visit[e_ind] = true;for (int j = 0; j < 60; j++)cost[e_ind][j] = 0;while (!q.empty()){int id = q.front();q.pop();for (int i = 0; i < G[id].size(); i++){int ide = G[id][i];int f = road[ide].from;if (update(ide) && !visit[f]){q.push(f);visit[f] = true;}}visit[id] = false;}double ans = Inf;for (int i = 0; i < 60; i++)ans = min(ans, cost[s_ind][i]);if (ans >= Inf) cout << "IMPOSSIBLE\n";else cout <<setprecision(10)<< ans << endl;}void Init(){amount = 0;for (int i = 0; i < N; i++){for (int j = 0; j < 60; j++) cost[i][j] = Inf;}record.clear();road.clear();memset(visit,0,sizeof(visit));cin >> starts >> ends;for (int i = 0; i < N; i++) G[i].clear();s_ind = find_location(starts);e_ind = find_location(ends);cin >> total;for (int i = 0; i < total; i++){string a, b;cin >> a >> b;int a_ind = find_location(a), b_ind = find_location(b);Road temp;temp.from = a_ind, temp.to = b_ind;cin >> temp.start >> temp.dur >> temp.per >> temp.delay;road.push_back(temp);G[b_ind].push_back(road.size()-1);}}void Deal(){Init();getRes();}
};int main(){int Case;cin >> Case;Solve a;while (Case--){a.Deal();}return 0;
}
UVA 1518 Train delays相关推荐
- uva 299 - Train Swapping
2019独角兽企业重金招聘Python工程师标准>>> 题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- 文本分类 之 有Attention的词向量平均模型 Word Average Model with Attention
这是一个文本分类的系列专题,将采用不同的方法有简单到复杂实现文本分类. 使用Stanford sentiment treebank 电影评论数据集 (Socher et al. 2013). 数据集可 ...
- 暑期集训4:栈,树,优先队列 例 : UVA - 514
2018学校暑期集训第四天--栈,树,优先队列 例题 -- UVA - 514 Rails There is a famous railway station in PopPush City. ...
- Matlab神经网络十讲(2): Create Configuration Train NeuralNet
1. Create Neural Network Object The easiest way to create a neural network is to use one of the netw ...
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...
- tf.train.MonitoredSession 简介
在run过程中的集成一些操作,比如输出log,保存,summary 等 基类一般用在infer阶段,训练阶段使用它的子类 tf.train.MonitoredTrainingSession 1 Mon ...
- TFRecord tf.train.Feature
一.定义 事先将数据编码为二进制的TFRecord文件,配合TF自带的多线程API,读取效率最高,且跨平台,适合规范化存储复杂的数据.上图为TFRecord的pb格式定义,可发现每个TFRecord由 ...
- [搜索]UVa 129 困难的串
题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...
最新文章
- mysql optimize_真正实现千人千面?教你用Optimize收割精准流量
- Labview串口通信
- vs如何设置对话框显示在最前面_“打开”对话框的使用
- Python如何引用豆瓣api镜像地址
- SQL 语句(原生)
- python的魔法方法
- IOS--多线程--GCD--在CGD中快速实现多线程的并发控制
- 三级计算机等级2021年9月考试准考证下载步骤
- ◎Vbs调用MsAgent组件,很有趣
- 【IDE】Intellij IDEA启动正常,但是任务栏不显示图标
- 获奖团队访谈录|“AI+视觉特征编码”赛道二等奖团队
- 破解 WIDCOMM 蓝牙驱动的方法
- 一招解决windows电脑禁用笔记本自带键盘问题
- docker: 打包h5项目的镜像
- 简单实现redis实现高并发下的抢购/秒杀功能
- 手机支付:合作之路才是正途
- html中点击文字变色,html选中文字 背景/字 变色
- Beyond Compare4试用过期解决方法
- 5分钟内完成Python键盘记录程序
- android输入法框架分析,Android输入法架构.ppt
热门文章
- steam饥荒mod编写,基础的lua语言学习笔记——第一期
- “工欲善其事,必先利其器”-- 教你几招如何选择合适的数据可视化工具
- 前端基础学习之css3-(border-image)实现边框图片自适应填充
- 本地使用Idea创建SpringBoot项目并给gitee托管
- 使用代理服务器打不开网页_代理服务器:信息安全表象下的另一面
- 【游戏编程扯淡精粹】TinySTL源码阅读
- 开源的PHP DKP系统
- STM32F103 - 延迟函数 -unfinished -unfinished-unfinished
- 基于Java实现的定时给微信好友发送消息
- 仿百度糯米页面 html5,Thinkphp5.0 仿百度糯米 开发多商家 电商平台(完整版)