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 numerous examples of using the few to defeat the many. There are VV (Numbers 11 to VV) fire-fighting points in ACM city. These fire-fighting points have EE roads to communicate with each other. Among them, there is a fire-fighting hero in the SS fire-fighting point, and the fire-fighting team is distributed in K fire-fighting points. If a fire-fighting point needs to be put out, the fire-fighting hero or the fire-fighting team must arrive as soon as possible, that is, to choose the shortest route to arrive.
Today, our fire-fighting heroes want to challenge the fire-fighting team. The challenge is to: The maximum value of the shortest path for a fire-fighting hero to go to others fire-fighting points is compared with the maximum value of the shortest path for a fire-fighting team to go to others fire-fighting points from any point in their fire-fighting points. Because firefighting heroes are different and run faster, the maximum value of the shortest path they get should be discounted first, that is, multiplied by a coefficient of \frac{1}{C}C1, and then compared. The smaller one wins. Who is the real firefighter in this situation?
Who is the real firefighter in this situation?
Input
The first line contains a positive integer T (1\le T \le 10)T(1≤T≤10), which indicates that there are TT cases of test data.
The format of each case of test data is as follows:
- Line 11 contains five positive integers V (1 \le V \le 1000)V(1≤V≤1000), E (V-1 \le E \le \frac{V*V}{2})E(V−1≤E≤2V∗V), S (1 \le S \le V)S(1≤S≤V), K (1\le K \le V)K(1≤K≤V) and C (1\le C\le 10)C(1≤C≤10), the meanings are shown above.
- Line 22 contains KK positive integers, which in turn denotes the location number of the fire-fighting point where the fire-fighting team is located.
In the next EE line, three positive integers i, j (1 \le i, j \le V)i,j(1≤i,j≤V) and L (1 \le L \le 10000)L(1≤L≤10000) per line. Represents a path, i, ji,j as the endpoint (fire-fighting point), LL as the length of the path.
Output
Each case of test data outputs one line, which is a integer. That is, the maximum value of the shortest path of the winner (If the fire hero wins, the maximum value before the discount should be output). A draw is also a victory for fire-fighting hero.
样例输入复制
1
4 7 3 2 2
1 4
1 2 7
1 3 2
1 4 6
2 1 1
2 4 1
3 2 1
3 4 3
样例输出复制
2
这个题当时交了89遍floyd,回去写了一遍超级源点,过了,这个垃圾题,是一个裸的超级源点,妈蛋,我就是读不懂他在说什么,这道题就是考察读题意。差评。
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
struct Node
{
int to, lat, val;
};
Node edge[1000005];
int head[1005],tot,dis[1005],N;
void add(int a, int b, int c)
{
edge[++tot].to = b;
edge[tot].val = c;
edge[tot].lat = head[a];
head[a] = tot;
}
void dijkstra(int yy)
{
priority_queue<pair<int,int>> pq;
for (int i = 1; i <= N; ++i)
dis[i] = inf;
dis[yy] = 0;
pq.push(make_pair(0,yy));
while (!pq.empty())
{
int s=pq.top().second;
pq.pop();
for (int i = head[s]; i; i = edge[i].lat)
{
int val = edge[i].to;
if (dis[val] > dis[s] + edge[i].val)
{
dis[val] = dis[s] + edge[i].val;
int w= dis[s] + edge[i].val;
pq.push(make_pair(-w,val));
}
}
}
}
int main()
{
int val, e, s, k, c;
int t, x;
scanf("%d", &t);
while (t--)
{
memset(head, 0, sizeof(head));
tot = 0;
scanf("%d %d %d %d %d", &N, &e, &s, &k, &c);
for (int i = 1; i <= k; ++i)
{
scanf("%d", &x);
add(0, x, 0);
add(x, 0, 0);
}
while (e--)
{
int a, b, dis;
scanf("%d %d %d", &a, &b, &dis);
add(a, b, dis),add(b,a,dis);
}
dijkstra(0);
int ans1 = -1;
for (int i = 1; i <= N; ++i) ans1 = max(ans1, dis[i]);
dijkstra(s);
int ans2= -1;
for (int i = 1; i <= N; ++i) ans2 = max(ans2, dis[i]);
if (ans1 * c < ans2)
printf("%d\n", ans1);
else
printf("%d\n", ans2);
}
return 0;
}
这题也没构造啥菊花图,这图那图的,用SPFA照样过,我真是个弟弟,89遍,我太垃圾了。
#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
#define Swap(a,b) a^=b^=a^=b
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define speed ios_base::sync_with_stdio(0)
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define INF 0x3f3f3f3f
#define maxn 100010
#define Ege 100000000
#define Vertex 1005
#define esp 1e-9
#define mp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
struct Node
{
int to, lat, val; //边的右端点,边下一条边,边权
};
Node edge[1000005];
int head[1005],tot,dis[1005],N,M,sb[1005],vis[1005];
void add(int from, int to, int dis)
{
edge[++tot].lat = head[from];
edge[tot].to = to;
edge[tot].val = dis;
head[from] = tot;
}
void spfa(int s)
{
memset(dis, 0x3f, sizeof(dis));
dis[0]=0;
memset(vis, 0, sizeof(vis));
vis[s] = 1;
dis[s] = 0;
queue<int>Q;
Q.push(s);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
vis[u] = 0;
for (int i = head[u];i;i = edge[i].lat) {
int to = edge[i].to;
int di = edge[i].val;
if (dis[to]>dis[u] + di) {
dis[to] = dis[u] + di;
if (!vis[to]) {
vis[to] = 1;
Q.push(to);
}
}
}
}
}
int main()
{
int val, e, s, k, c;
int t, x;
scanf("%d", &t);
while (t--)
{
memset(head, 0, sizeof(head));
tot = 0;
scanf("%d %d %d %d %d", &N, &e, &s, &k, &c);
for (int i = 1; i <= k; ++i)
{
scanf("%d", &x);
add(0, x, 0);
add(x, 0, 0);
}
while (e--)
{
int a, b, dis;
scanf("%d %d %d", &a, &b, &dis);
add(a, b, dis),add(b,a,dis);
}
spfa(0);
int ans1 = -1;
for (int i = 1; i <= N; ++i) ans1 = max(ans1, dis[i]);
spfa(s);
int ans2= -1;
for (int i = 1; i <= N; ++i) ans2 = max(ans2, dis[i]);
if (ans1 * c < ans2)
printf("%d\n", ans1);
else
printf("%d\n", ans2);
}
return 0;
}
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 B. Fire-Fighting Hero
题目链接:https://nanti.jisuanke.com/t/41349 题意:有一个灭火英雄,和一个灭火团队,一个人与一个团队比较. 灭火英雄到其他灭火点的最短路最大值,与一个团队到其他灭火点 ...
- 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 C. Hello 2019(动态dp)
题意:要找到一个字符串里面存在子序列9102 而不存在8102 输出最小修改次数 思路:对于单次询问 我们可以直接区间dpOn求出最小修改次数 但是对于多次询问 我在大部分题解看到的解释一般是用线段树 ...
随机推荐
- ThinkPHP3.2.3集成微信分享JS-SDK实践
先来看看微信分享效果:在没有集成微信分享js-sdk前是这样的:没有摘要,缩略图任意抓取正文图片 在集成微信分享js-sdk后是这样的:标题,摘要,缩略图自定义 一.下载微信SDK开发包下载地址:ht ...
- CH5105 Cookies (线性dp)
传送门 解题思路: 贪心的想,贪婪值越大的孩子应该分得更多的饼干,那么先sort一遍在此基础上进行dp.最直观的方向,可以设dp[i][j]为前i个孩子一共分得j块饼干的怨恨最小值.然后转移第i+1个 ...
- 【Selenium03篇】python+selenium实现Web自动化:元素三类等待,多窗口切换,警告框处理,下拉框选择
一.前言 最近问我自动化的人确实有点多,个人突发奇想:想从0开始讲解python+selenium实现Web自动化测试,请关注博客持续更新! 这是python+selenium实现Web自动化第三篇博 ...
- java课程设计之--Elasticsearch篇
一.团队课程设计博客链接 https://www.cnblogs.com/Rasang/p/12169899.html 二.个人负责模块或任务说明 2.1Elasticsearch简介 Elastic ...
- linux常用命令整理(一)
1.sort(排序) 典型例题:sort -t: -k3n /etc/passwd 以冒号为分隔符根据第三个域的数字大小进行排序(默认分隔符是空格) 2.uniq(去除文件中的连续重复行) 典型例题: ...
- 别再问我 new 字符串创建了几个对象了!我来证明给你看!
我想所有 Java 程序员都曾被这个 new String 的问题困扰过,这是一道高频的 Java 面试题,但可惜的是网上众说纷纭,竟然找不到标准的答案.有人说创建了 1 个对象,也有人说创建了 2 ...
- 【转】解决存储过程执行快,但C#程序调用执行慢的问题
这两天遇到一个问题令人比较郁闷,一个大概120行左右的存储过程在SQL Server2012的查询分析器里面执行,速度非常理想,1秒不到,即可筛选抓取到大概500条数据记录.但在C#程序代码里调用,就 ...
- L13过拟合欠拟合及其解决方案
过拟合.欠拟合及其解决方案 过拟合.欠拟合的概念 权重衰减 丢弃法 模型选择.过拟合和欠拟合 训练误差和泛化误差 在解释上述现象之前,我们需要区分训练误差(training error)和泛化误差(g ...
- ASE课程总结 by 张葳
本期ASE课程分为两个阶段,第一阶段的personal project与第二阶段的team project,其中,第一阶段旨在锻炼我们个人的问题解决能力和编程能力,第二阶段则锻炼主要我们的管理能力,合 ...
- S7通信协议之你不知道的事儿
在电气学习的路上,西门子PLC应该是我的启蒙PLC,从早期的S7-300/400 PLC搭建Profibus-DP网络开始接触,到后来的S7-200Smart PLC,再到现在的S7-1200/150 ...