美团2018年CodeM大赛-初赛B轮 B 配送(最短路)
美团2018年CodeM大赛-初赛B轮 B 配送
题意
题解
对于每个任务,只要从上个任务的终点出发即可。
时间、地点很少,可以算出每个地点-时间的最小花费。
以题目描述的起点终点起始结束时间建图,很暴力的跑最短路即可。
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---
const int inf = 2e9;
int n, m, k;
struct Task {
int pos;
string tim;
bool operator < (const Task &c) const {
return tim < c.tim;
}
}task[11];
struct Edge {
int v, p;
string st, ed;
Edge(int v, int p, string st, string ed) : v(v), p(p), st(st), ed(ed) {}
};
vector<Edge> g[111];
map<string, int> dis[111];
void dij(int pos, string tim) {
rep(i, 1, k+1) dis[i].clear();
dis[pos][tim] = 0;
priority_queue<pair<int, pair<int, string> > > que;
que.push(mp(0, mp(pos, tim)));
while(!que.empty()) {
auto u = que.top(); que.pop();
int d = -u.fi;
pos = u.se.fi; tim = u.se.se;
if(d != dis[pos][tim]) continue;
for(auto i : g[pos]) {
int v = i.v, p = i.p;
int t = dis[pos][tim] + p;
if(tim < i.st && (!dis[v].count(i.ed) || dis[v][i.ed] > t)) {
dis[v][i.ed] = t;
que.push(mp(-t, mp(v, i.ed)));
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n >> m >> k;
rep(i, 0, n) {
string s1, s2;
cin >> task[i].pos >> s1 >> s2;
task[i].tim = s1 + " " + s2;
}
sort(task, task+n);
rep(i, 0, m) {
int u, v, p;
string st, ed;
cin >> u >> v >> p >> st >> ed;
rep(j, 1, 8) {
string t1 = "2018.07.0" + to_string(j) + " " + st;
string t2 = "2018.07.0" + to_string(j) + " " + ed;
g[u].pb(Edge(v, p, t1, t2));
}
}
int pos = 1, ans = 0;
string tim = "2018.06.30 23:59:59.999";
rep(i, 0, n) {
dij(pos, tim);
int res = inf;
for(auto j : dis[task[i].pos]) {
if(j.fi < task[i].tim) res = min(res, j.se);
else break;
}
if(res == inf) {
ans = inf;
break;
}
ans += res;
pos = task[i].pos;
tim = task[i].tim;
}
if(ans == inf) ans = -1;
cout << ans << endl;
return 0;
}
美团2018年CodeM大赛-初赛B轮 B 配送(最短路)的更多相关文章
- 美团2018年CodeM大赛-初赛B轮 C题低位值
试题链接:https://www.nowcoder.com/acm/contest/151/C 定义lowbit(x) =x&(-x),即2^(p-1) (其中p为x的二进制表示中,从右向左数 ...
- 美团2017年CodeM大赛-初赛B轮-黑白树
https://ac.nowcoder.com/acm/problem/13249 链接:https://ac.nowcoder.com/acm/problem/13249来源:牛客网 题目描述 一棵 ...
- 美团2017年CodeM大赛-初赛B轮 黑白树 (树形dp)
大意: 给定树, 初始每个点全为白色, 点$i$有权值$k_i$, 表示选择$i$后, 所有距离$i$小于$k_i$的祖先(包括i)会变为黑色, 求最少选多少个点能使所有点变为黑色. 链上情况的话, ...
- 美团2017年CodeM大赛-初赛A轮 C合并回文子串
区间dp一直写的是递归版本的, 竟然超时了, 学了一下非递归的写法. #include <iostream> #include <sstream> #include <a ...
- 美团2018年CodeM大赛-资格赛 分数 暴力模拟
链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...
- 美团2018年CodeM大赛-资格赛
https://www.nowcoder.com/acm/contest/138#question A.下单 水题…… B.可乐 题意:求期望 代码: #include<iostream> ...
- 2018美团CodeM编程大赛初赛B轮 A题开关灯
题目描述 美团的办公室一共有n层,每层有m个会议室,可以看成是一个n*m的网格图.工程师们每天的工作需要协作的地方很多,经常要到会议室开会解决各种问题.公司是提倡勤俭节约的,因此每次会议室只在使用时才 ...
- CodeM美团点评编程大赛初赛A轮
因为语文太差弃赛,第一个追及问题看不懂我就弃赛了.打进复赛确实挺难的,补一下题,锻炼下就行了. 身体训练 时间限制:1秒 空间限制:32768K 美团外卖的配送员用变速跑的方式进行身体训练.他们训练的 ...
- codeM美团编程大赛初赛B轮D题
[编程题] 模 时间限制:1秒空间限制:32768K 给定四个正整数a,b,c,k,回答是否存在一个正整数n,使得a*n在k进制表示下的各位的数值之和模b为c.输入描述:第一行一个整数T(T < ...
随机推荐
- maven在pom文件中添加你想要的jar包
概述:POM 文件里面的依赖jar包经常需要添加, 仅需要在google中代码查找 :maven 你需的jar包名称 repository 用了Maven,所需的JAR包就不能再像往常一样,自己找到并 ...
- Hudson-ci/Using Hudson/Installing Hudson/Installing Hudson RPM--官方文档
< Hudson-ci | Using Hudson | Installing Hudson(Redirected from Hudson-ci/Installing Hudson RPM) ...
- mysql 最小配置 及 安装
[mysqld] # 设置3306端口 port= # 设置mysql的安装目录 basedir=D:\-Installer\-MySQL\mysql--winx64 # 设置mysql数据库的数据的 ...
- 图标插件FusionChartsFree
二.介绍 Ø FusionCharts 是InfoSoft Global 公司的一个产品,InfoSoft Global 公司是专业的Flash 图形方案提供商,他们还有几款其他的,基于Flash 技 ...
- Java中多个集合的交集,并集和差集
一.交集 java中交集使用 A.retainAll(B) ,交集的结果在集合A中. import org.junit.Test; import java.util.HashSet; import j ...
- 【SSH网上商城项目实战06】基于DataGrid的数据显示
转自:https://blog.csdn.net/eson_15/article/details/51322262 1. 回顾一下第4节内容 在第4节中,我们使用EasyUI搭建好了左侧菜单栏,并且通 ...
- ES6学习笔记(四)-数值扩展
PS: 前段时间转入有道云笔记,体验非常友好,所以笔记一般记录于云笔记中,每隔一段时间,会整理一下, 发在博客上与大家一起分享,交流和学习. 以下:
- Window ssh免密登录到远程Linux服务器
SSH采用的是”非对称密钥系统”,即耳熟能详的公钥私钥加密系统. 1. 基于口令的安全验证 这种方式使用用户名密码进行联机登录,一般情况下我们使用的都是这种方式.整个过程大致如下: (1)客户端发起连 ...
- SQL Server Metadata
http://www.devart.com/dotconnect/sqlserver/docs/MetaData.htmlhttps://msdn.microsoft.com/en-us/librar ...
- [HAOI2009]逆序对数列(加强)
ZJL 的妹子序列 暴力就是 \(\Theta(n\times m)\) 如果 \(n,m \le 10^5\) ? 考虑问题的转换,设 \(a_i\) 表示 \(i\) 小的在它后面的数的个数 \( ...