The 2019 Asia Nanchang First Round Online Programming Contest B. Fire-Fighting Hero
题目链接:https://nanti.jisuanke.com/t/41349
题意:有一个灭火英雄,和一个灭火团队,一个人与一个团队比较。
灭火英雄到其他灭火点的最短路最大值,与一个团队到其他灭火点的最短路的最大距离*C,进行比较。
如果一个团队的一个人在k点,那么k点的最短路就是0,这样,我们可以构建一个虚拟点“0”点,跑团队的最短路
可以让“0”点到其他团队队员点为0,到其他点为inf,然后跑一次最短路就可以了,下面的代码是比赛时候的,懒得改,直接很难看的写了。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std; typedef long long LL;
#define inf 1e9
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--) const int N = ;
bool vis[N];
int mp[N][N];
bool fired[N];
int team[N];
int dis[N];
int V,E,S,K,C; int dijkstra(int s){ rep(i,,V) vis[i] = false; if(s){
rep(i,,V) dis[i] = inf;
rep(i,,V) dis[i] = mp[s][i];
vis[s] = true; rep(i,,V){//团队的 int x = -;
int c = inf; rep(j,,V){ if(!vis[j] && c > dis[j]) x = j, c = dis[j];
}
if(x == -) continue; vis[x] = true;
rep(p,,V){
if(!vis[p] && dis[x] + mp[x][p] < dis[p]){
dis[p] = dis[x] + mp[x][p];
}
} }
}
else{//英雄的
rep(i,,V) dis[i] = inf;
rep(i,,K) dis[team[i]] = ;
vis[s] = true; rep(i,,V){ int x = -;
int c = inf; rep(j,,V){ if(!vis[j] && c > dis[j]) x = j, c = dis[j];
}
if(x == -) continue; vis[x] = true;
rep(p,,V){
if(!vis[p] && dis[x] + mp[x][p] < dis[p]){
dis[p] = dis[x] + mp[x][p];
}
} }
} int ans = ;
rep(i,,V){ if(dis[i] == inf) continue;
if(fired[i]) ans = max(ans,dis[i]);
} return ans;
} int main(){ ios::sync_with_stdio(false);
cin.tie(); int T;
cin >> T; int p = ;
int q = ;
while(T--){
cin >> V >> E >> S >> K >> C; rep(i,,V) rep(j,,V){
if(i == j) mp[i][j] = ;
else mp[i][j] = inf;
} rep(i,,K){
cin >> team[i];
} int u,v,w; rep(i,,E){
cin >> u >> v >> w;
fired[v] = true;
if(mp[u][v] > w){
mp[u][v] = mp[v][u] = w;
}
} p = dijkstra(S);//英雄 q = dijkstra();//团队 if(p <= q*C) cout << p << endl;
else cout << q << endl;
} getchar();getchar(); return ;
}
The 2019 Asia Nanchang First Round Online Programming Contest B. Fire-Fighting Hero的更多相关文章
- The 2019 Asia Nanchang First Round Online Programming Contest
传送门 A. Enju With math problem 题意: 给出\(a_1,\cdots,a_{100}\),满足\(a_i\leq 1.5*10^8\). 现在问是否存在一个\(pos\), ...
- The 2019 Asia Nanchang First Round Online Programming Contest C(cf原题,线段树维护矩阵)
题:https://nanti.jisuanke.com/t/41350 分析:先将字符串转置过来 状态转移,因为只有5个状态,所以 i 状态到 j 状态的最小代价就枚举[i][k]->[k][ ...
- The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master
题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放 ...
- The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item
The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\( ...
- H. The Nth Item(The 2019 Asia Nanchang First Round Online Programming Contest)
题意:https://nanti.jisuanke.com/t/41355 给出N1,计算公式:A=F(N)Ni=Ni-1 ^ (A*A),F为类斐波那契需要矩阵快速幂的递推式. 求第k个N. 思路: ...
- E.Magic Master(The 2019 Asia Nanchang First Round Online Programming Contest)
直接模拟orhttps://blog.csdn.net/liufengwei1/article/details/100643831
- The 2019 Asia Nanchang First Round Online Programming Contest(B,E)
B. Fire-Fighting Hero 题意:一个消防员和多个队伍比赛,比较所有地方的最短路的最大值,消防员最后的值要乘1/C,求胜利的一方的最短路的最大值是多少.一直没读懂正确题意(内疚). 思 ...
- The 2019 Asia Nanchang First Round Online Programming Contest B Fire-Fighting Hero(阅读理解)
This is an era of team success, but also an era of heroes. Throughout the ages, there have been nume ...
- The 2019 Asia Nanchang First Round Online Programming Contest C. Hello 2019(动态dp)
题意:要找到一个字符串里面存在子序列9102 而不存在8102 输出最小修改次数 思路:对于单次询问 我们可以直接区间dpOn求出最小修改次数 但是对于多次询问 我在大部分题解看到的解释一般是用线段树 ...
随机推荐
- git的安装及使用
介绍 1.Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版 ...
- [LeetCode] 662. Maximum Width of Binary Tree 二叉树的最大宽度
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- [LeetCode] 465. Optimal Account Balancing 最优账户平衡
A group of friends went on holiday and sometimes lent each other money. For example, Alice paid for ...
- [LeetCode] 113. Path Sum II 二叉树路径之和之二
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- [LeetCode] 6. ZigZag Conversion 之字型转换字符串
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- Codeforces 1204D Kirk and a Binary String - 数学
题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表 ...
- ORACLE 10g 升级 11g问题汇总(转载文)
按照计划开始了生产库的升级,环境基于linux 64位. uname: Linux 2.6.18-308.el5 #1 SMP Fri Jan 27 17:17:51 EST 2012 x86_64 ...
- windows上MongoDB远程访问配置
今天用另一台机器上的MongoDB,但是使用本地连接时,没问题 换成IP地址时,出现 解决的方法,修改配置文件 systemLog: destination: file path: d:/Mongod ...
- office常用技巧汇总
1.excel篇 (1)一次选择多行 可以利用SHIFT+鼠标实现,点第一行,按下鼠标,点200行,就能实现1~200行选择了. 总结:就是一直按住shift键,鼠标点击要选择的首行,再点击尾行.
- Web应急:搜索引擎劫持
当你直接打开网址访问网站,是正常的,可是当你在搜索引擎结果页中打开网站时,会跳转到一些其他网站,比如博彩,虚假广告,淘宝搜索页面等.是的,你可能了遇到搜索引擎劫持. 现象描述 从搜索引擎来的流量自动跳 ...