题目链接: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的更多相关文章

  1. 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\), ...

  2. The 2019 Asia Nanchang First Round Online Programming Contest C(cf原题,线段树维护矩阵)

    题:https://nanti.jisuanke.com/t/41350 分析:先将字符串转置过来 状态转移,因为只有5个状态,所以 i 状态到 j 状态的最小代价就枚举[i][k]->[k][ ...

  3. The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master

    题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放 ...

  4. The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item

    The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\( ...

  5. 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. 思路: ...

  6. E.Magic Master(The 2019 Asia Nanchang First Round Online Programming Contest)

    直接模拟orhttps://blog.csdn.net/liufengwei1/article/details/100643831

  7. The 2019 Asia Nanchang First Round Online Programming Contest(B,E)

    B. Fire-Fighting Hero 题意:一个消防员和多个队伍比赛,比较所有地方的最短路的最大值,消防员最后的值要乘1/C,求胜利的一方的最短路的最大值是多少.一直没读懂正确题意(内疚). 思 ...

  8. 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 ...

  9. The 2019 Asia Nanchang First Round Online Programming Contest C. Hello 2019(动态dp)

    题意:要找到一个字符串里面存在子序列9102 而不存在8102 输出最小修改次数 思路:对于单次询问 我们可以直接区间dpOn求出最小修改次数 但是对于多次询问 我在大部分题解看到的解释一般是用线段树 ...

随机推荐

  1. Regular Forestation CodeForces - 1252F(树同构)

    Regular Forestation \[ Time Limit: 1000 ms\quad Memory Limit: 262144 kB \] 题意 给出一个节点为 \(n\) 的树,问删掉树上 ...

  2. [Taro] Taro 环境安装 (一)

    Taro  环境安装 Taro是一个前端小程序框架,通过这个框架写一套代码,再通过 Taro 的编译工具,就可以将源代码分别编译出可以在不同端(微信/百度/支付宝/字节跳动小程序.H5.React-N ...

  3. 日常笔记3关于bool类型数组初始化的问题

    一般会有两种考虑,全为true或全为false 赋值方式: <1>memset(boolArray,0,sizeof(Array)); 头文件:#include<cstring> ...

  4. 8.9 NOIP模拟测试15 建设城市(city)+轰炸行动(bomb)+石头剪刀布(rps)

    鉴于T3的惨烈程度,我决定先来颓篇题解. T1 建设城市(city) 挡板法+容斥 m个建设队分成n组,每组必须有一个,先不考虑上限,共有 C(m-1,n-1)种方案. 有i个组是超过k个的,容斥掉 ...

  5. [LeetCode] 685. Redundant Connection II 冗余的连接之二

    In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) f ...

  6. [LeetCode] 248. Strobogrammatic Number III 对称数之三

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  7. 这篇文章主要讲解C#中的泛型,泛型在C#中有很重要的地位,尤其是在搭建项目框架的时候。

    一.什么是泛型 泛型是C#2.0推出的新语法,不是语法糖,而是2.0由框架升级提供的功能. 我们在编程程序时,经常会遇到功能非常相似的模块,只是它们处理的数据不一样.但我们没有办法,只能分别写多个方法 ...

  8. 阿里云ECS服务器CentOS7.2安装Python2.7.13

    阿里云ECS服务器CentOS7.2安装Python2.7.13 yum中最新的也是Python 2.6.6,只能下载Python 2.7.9的源代码自己编译安装. 操作步骤如下: 检查CentOS7 ...

  9. UWP 使用Launcher 启动迅雷

    不得不说UWP有些地方真的不方便! 另外也要夸一下迅雷,还是蛮不错的! 代码 await Launcher.LaunchUriAsync(new Uri("magnet:?xt") ...

  10. Redis(九)高可用专栏之Sentinel模式

    本文讲述Redis高可用方案中的哨兵模式--Sentinel,RedisClient中的Jedis如何使用以及使用原理. Redis主从复制 Redis Sentinel模式 Jedis中的Senti ...