B. Fire-Fighting Hero

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

思路:图论题-单源最短路径:添加一个顶点,连接各个救火团队所在的救火点,路径长度均设为 0,设该顶点为源,即变成了单源最短路径问题。使用两次Dijkstra算法可求出两个最短路径 的最大值。比较时将救火团队的乘以T进行比较可避免分数操作。(题解)

AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6+;
const ll INF = 1e18 + ;
typedef pair<ll,int> P;
int n , m;
struct edge{
int to;
ll cost;
}es[maxn];
vector <edge> G[maxn];
ll d[maxn];
ll dijkstra(int s)
{
priority_queue<P,vector<P>,greater<P> > que;
fill(d,d+n+,INF);
d[s] = ;
que.push(P(,s));
while(!que.empty())
{
P p= que.top();que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = ;i < G[v].size();i++)
{
edge e = G[v][i];;
if(d[e.to] > d[v] + e.cost)
{ d[e.to]= d[v] + e.cost;
que.push(P(d[e.to],e.to));
}
}
}
ll a = -INF;
for(int i = ;i <= n;i++){
a = max(a, d[i]);
}
return a;
}
ll a[maxn];
int cnt;
void add(int a, int b, ll c)
{
es[cnt].to = b;
es[cnt].cost = c;
G[a].push_back(es[cnt++]);
es[cnt].to = a;
es[cnt].cost = c;
G[b].push_back(es[cnt++]);
}
int main()
{
std::ios::sync_with_stdio(false);
int t, S, k;
ll C;
cin >> t;
while(t--)
{
cin >> n >> m >> S >> k >> C;
int u,v,w;
cnt = ;
for(int i = ;i <= n;i++)G[i].clear();
for(int i = ;i <= k;i++) cin >> a[i];
for(int i = ;i < m;i++)
{
cin >> u >> v >> w;
add(u, v, w);
}
ll z = dijkstra(S);
// cout << z << " = z" << endl;
for(int i = ;i <= k;i++)
add(,a[i],);
ll x = dijkstra();
//cout << x << " " << endl;
cout<<((z <= x * C) ? z : x) <<endl;
}
return ;
}

E. Magic Master

思路:真没想过就是暴力模拟就行了,想了半天,一脸懵逼。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n, m, q;
scanf("%d%d%d",&n, &m, &q);
deque<int> dq;
for(int i = n;i > ;i--)
{
dq.push_front(i);
if(i == )break;
for(int j = ;j <= m;j++)
{
int x = dq.back();
dq.pop_back();
dq.push_front(x);
}
}
while(q--)
{
int a;
scanf("%d",&a);
printf("%d\n",dq[a - ]);
}
}
return ;
}

H. The Nth Item

待补

The 2019 Asia Nanchang First Round Online Programming Contest(B,E)的更多相关文章

  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 B. Fire-Fighting Hero

    题目链接:https://nanti.jisuanke.com/t/41349 题意:有一个灭火英雄,和一个灭火团队,一个人与一个团队比较. 灭火英雄到其他灭火点的最短路最大值,与一个团队到其他灭火点 ...

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

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

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

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

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

  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. 54、tensorflow手写识别的高级版本

    ''' Created on 2017年3月4日 @author: weizhen ''' import tensorflow as tf def weight_variable(shape): in ...

  2. 数据库SQL调优的几种方式(转)

    原文地址:https://blog.csdn.net/u010520146/article/details/81161762 在项目中,SQL的调优对项目的性能来讲至关重要,所有掌握常见的SQL调优方 ...

  3. Centos6下实现Nginx+Tomcat实现负载均衡及监控

    在性能测试过程中,我们可能会关注很多指标,比如CPU.IO.网络.磁盘等,通过这些指标大致可以判断哪个环节遇到了性能瓶颈,但是当这些指标无法判断出性能瓶颈时,我们可能就需要对一些中间件进行监控,比如N ...

  4. 【lua学习笔记】——在sublime中配置Lua运行环境

    一.让Sublime可以运行lua脚本 打开sublime 选择tools-->Build System-->New Build System   在新出现的文件中输入如下内容: { &q ...

  5. LOJ #103. 子串查找 (Hash)

    题意 给定两个字符串 \(A\) 和 \(B\),求 \(B\) 在 \(A\) 中的出现次数. 思路 这是一道 \(KMP\) 的模板题. 不过 \(Hash\) 是个好东西,可以用 \(Hash\ ...

  6. Python文章导航

    1.Python+Eclipse安装.配置: http://www.cnblogs.com/rhyswang/p/8087752.html 2.数学运算及math库: http://www.cnblo ...

  7. 好947 Mybatis 配置resultMap 带參数查询Map 注意selectOne数据库返回结果一条数据库 否则会报错

    //TMD 写几个demo 还有大站採集 <a target=_blank href="http://hao947.com/" target="_blank&quo ...

  8. React-native 关于键盘遮挡界面问题

    //引入 KeyboardAvoidingView import { KeyboardAvoidingView } from 'react-native'; //使用 KeyboardAvoiding ...

  9. python爬虫爬取ip记录网站信息并存入数据库

    import requests import re import pymysql #10页 仔细观察路由 db = pymysql.connect("localhost",&quo ...

  10. jQuery实现点击按钮展开和收起

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...