B. Fire-Fighting Hero (dijstra优先队列+bfs)

题意:刚开始看错题了,以为是k次dijkstra,但是wa了,后来队友指正后发现挺水的。求S到其它点的最短路的最大值ans1,然后求其它点到指定k个点之一的最短路的最大值ans2。比较ans1和ans2即可。

思路:用dijstra优化队列求ans1,k次优先队列bfs求ans2即可。

AC code:

#include<cstdio>
#include<algorithm>
#include<cctype>
#include<queue>
using namespace std; inline int read()
{
int x=,f=; char ch=;
while(!isdigit(ch)) {f|=ch=='-';ch=getchar();}
while(isdigit(ch)) x=(x<<)+(x<<)+(ch^),ch=getchar();
return f?-x:x;
}
const int maxn=;
const int maxm=5e5+;
const int inf=0x3f3f3f3f;
int T,n,m,s,k,c,cnt,head[maxn],isk[maxn],dist[maxn],vis[maxn];
int ans1,ans2; struct node1{
int v,w,nex;
}edge[maxm]; void adde(int u,int v,int w){
edge[++cnt].v=v;
edge[cnt].w=w;
edge[cnt].nex=head[u];
head[u]=cnt;
} struct node2{
int w,id;
node2(){}
node2(int w,int id):w(w),id(id){}
}; bool operator < (const node2& a,const node2& b){
return a.w>b.w;
} void dijkstra(int s)
{
priority_queue<node2> que;
for(int i=; i<=n; i++)
dist[i]=inf,vis[i]=;
dist[s]=;
que.push(node2(,s));
while(!que.empty())
{
int u=que.top().id;
que.pop();
if(vis[u]) continue;
vis[u]=;
for(int i=head[u];i;i=edge[i].nex)
{
int v=edge[i].v;
int w=edge[i].w;
if(dist[v]>dist[u]+w)
{
dist[v]=dist[u]+w;
node2 rec;
rec.id=v;
rec.w=dist[v];
que.push(rec);
}
}
}
} int bfs(int s){
priority_queue<node2> que;
for(int i=; i<=n; ++i)
vis[i]=;
que.push(node2(,s));
while(!que.empty()){
node2 now=que.top();que.pop();
int nid=now.id,nw=now.w;
if(vis[nid]) continue;
vis[nid]=;
if(isk[nid])
return nw;
for(int i=head[nid];i;i=edge[i].nex){
int v=edge[i].v;
int w=edge[i].w;
que.push(node2(nw+w,v));
}
}
} int main(){
T=read();
while(T--){
n=read(),m=read(),s=read(),k=read(),c=read();
cnt=;
ans1=ans2=;
for(int i=;i<=n;++i)
head[i]=,isk[i]=;
for(int i=;i<=k;++i)
isk[read()]=;
for(int i=;i<=m;++i){
int u=read(),v=read(),w=read();
adde(u,v,w);
adde(v,u,w);
}
dijkstra(s);
for(int i=;i<=n;++i)
ans1=max(ans1,dist[i]);
for(int i=;i<=n;++i){
if(isk[i]) continue;
ans2=max(ans2,bfs(i));
}
if(ans1<=c*ans2) printf("%d\n",ans1);
else printf("%d\n",ans2);
}
return ;
}

E. Magic Master(暴力)

题意:模拟。

思路:按照题意倒着模拟即可,比赛时不敢暴力,看着会超空间时间,事实证明比赛时应该放开胆子取尝试。

AC code:

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std; int T,n,m,Q;
struct node{
int q,id,ans;
}query[]; bool cmp1(const node& a,const node& b){
return a.q>b.q;
} bool cmp2(const node& a,const node& b){
return a.id<b.id;
} int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&Q);
for(int i=;i<=Q;++i){
scanf("%d",&query[i].q);
query[i].id=i;
}
sort(query+,query++Q,cmp1);
queue<int> que;
for(int i=n;i>=;--i){
if(!que.empty()){
for(int j=;j<=m;++j){
int tmp=que.front();que.pop();
que.push(tmp);
}
}
que.push(i);
}
int cnt=;
for(int i=n;i>=;--i){
int tmp=que.front();que.pop();
if(i==query[cnt].q)
query[cnt++].ans=tmp;
if(cnt>Q) break;
}
sort(query+,query++Q,cmp2);
for(int i=;i<=Q;++i)
printf("%d\n",query[i].ans);
}
return ;
}

G. Pangu Separates Heaven and Earth(签到题)

题意:水题,按要求输出即可。

AC code:

#include<cstdio>
#include<algorithm>
using namespace std; int T;
int a; int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&a);
if(a==) printf("18000\n");
else printf("0\n");
}
return ;
}

2019icpc南昌网络赛的更多相关文章

  1. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  2. 2019icpc南昌网络赛_I_Yukino With Subinterval

    题意 给定一个序列,两种操作,单点修改,询问区间\([l,r]\)值域在\([x,y]\)范围内的连续段个数. 分析 原数组为\(a\),构造一个新的数组\(b\),\(b[i]=(a[i]==a[i ...

  3. 2019ICPC南昌网络赛总结

    打的很崩的一场比赛.上来签到题我就wa了一发,感觉在梦游.然后我开了H题,队友开B题,f(n)=3f(n-1)+2f(n)傻子都知道矩阵快速幂,但是1e7的强制在线必须把logn优化,然后试图打表寻找 ...

  4. 2019ICPC南昌网络赛C Hello 2019

    题意:给出一个字符串,每次询问一个区间[l,r],求使得这个区间含有9102但不含有8102最少要删掉几个字符 首先我们考虑将串反转,这样就变成了含有2019但不含有2018的问题了 我们构建一个状态 ...

  5. dp--2019南昌网络赛B-Match Stick Game

    dp--2019南昌网络赛B-Match Stick Game Xiao Ming recently indulges in match stick game and he thinks he is ...

  6. 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)

    题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...

  7. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  8. ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval

    ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...

  9. 南昌网络赛C.Angry FFF Party

    南昌网络赛C.Angry FFF Party Describe In ACM labs, there are only few members who have girlfriends. And th ...

随机推荐

  1. 024_STM32程序移植之_ESP8266_TCP

    (一)实验目的:编写电脑软件通过ESP8266传输数据给STM32的,下面这张图 (二)上面只是简单地图,视频比较全面 视频教程:https://v.qq.com/x/page/o0829zs7iop ...

  2. HTML的列表,表格与媒体元素

    一.无序列表 <ul>                            <li>无序列表</li>                            &l ...

  3. Codeforces Round #571 (Div. 2)

    A. Vus the Cossack and a Contest 签. #include <bits/stdc++.h> using namespace std; int main() { ...

  4. 5.3.3 自定义writable和RawComparatorWritable

    5.3.3 自定义writable (1)构造员工writable Hadoop虽然已经实现了一些非常有用的Writable,而且你可以使用他们的组合做很多事情,但是如果你想构造一些更加复杂的结果,你 ...

  5. 动态拼接tr,th

    var dltable=''; // <c:forEach items="data" var="data" ></c:forEach> ...

  6. Vue图片浏览组件v-viewer,支持旋转、缩放、翻转等操作

    v-viewer 用于图片浏览的Vue组件,支持旋转.缩放.翻转等操作,基于viewer.js. 从0.x迁移 你需要做的唯一改动就是手动引入样式文件: 1 import 'viewerjs/dist ...

  7. mybatis中foreach参数过多效率很慢的优化

    foreach 后面in 传入的参数有1万条,#和$是有效率区别的,$的效率远高于#,上篇文章做了比较. 但没达到我的理想结果. 1. 更改方式,把foreach 去掉,改成拼装方式, 参数直接拼装成 ...

  8. JS合并多个数组去重算法

    var arr1 = ['a','b']; var arr2 = ['a','c','d']; var arr3 = [1,'d',undefined,true,null]; //合并两个数组,去重 ...

  9. Csdn账号如何注销?

    Csdn账号如何注销?   请在ios端app设置内注销 ios端注销在设置页面的底部左下角,andriod在2019.07月底更新,即可支持   文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎 ...

  10. Editplus的运行JAVA的配置

    工具--->参数设置