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. pyecharts v1 版本 学习笔记 折线图,面积图

    折线图 折线图 基本demo import pyecharts.options as opts from pyecharts.charts import Line c = ( Line() .add_ ...

  2. windows下去掉快捷方式图标的小箭头的几种方法

    去掉快捷方式图标的小箭头的几种方法 第一种: 点开始菜单,点运行,输入以下命令后回车.即可解决 cmd /k reg delete "HKEY_CLASSES_ROOT\lnkfile&qu ...

  3. windows游戏编程键盘

    键盘 首先我们来看一下键盘常用消息 键盘的消息处理过程 键盘消息会有击键消息和字符消息 键盘消息的附加参数 wParam:非系统键的虚拟码 lParam: windows常用虚拟键码及对应的按键

  4. 7月清北学堂培训 Day 2

    今天是林永迪老师的讲授~ 继续昨日的贪心内容. 我们继续看例题: 分析样例的过河方法: 首先1和2先过河,总时间为2: 然后1回来,总时间为3: 然后5和10过河,总时间为13: 然后2回来,总时间为 ...

  5. redis之哨兵集群

    一.主从复制背景问题 Redis主从复制可将主节点数据同步给从节点,从节点此时有两个作用: 一旦主节点宕机,从节点作为主节点的备份可以随时顶上来. 扩展主节点的读能力,分担主节点读压力. 但是问题是: ...

  6. 微信小程序之简单记账本开发记录(三)

    昨天已经编辑了主界面,在wxml文件中设置好跳转链接之后,就可以进行下一步的开发了 在pages中建立一个新的页面文件夹作为之后的支出页面 编辑后台,今天先搭建大致界面

  7. Memcached 之在win10上的安装

    一.下载 http://static.runoob.com/download/memcached-win64-1.4.4-14.zip 二.安装 memcached <1.4.5 版本安装 1. ...

  8. Windows Form, Ok, Cancel button

    1. 为button设置DialogResult property为非None值, 可以关闭父窗口,并使父窗口的DialogResult property返回相应的值. http://msdn.mic ...

  9. benchmark在postgresql上的安装及使用

     BenchmarkSQL是一款经典的开源数据库测试工具,内嵌了TPCC测试脚本,可以对EnterpriseDB.PostgreSQL.MySQL.Oracle以及SQL Server等数据库直接进行 ...

  10. 008-多线程-锁-JUC锁-CyclicBarrier【让一组线程到达一个屏障(也可以叫同步点)时被阻塞,直到最后一个线程到达屏障时,屏障才会开门,所有被屏障拦截的线程才会继续运行】

    一.概述 “循环栅栏”.大概的意思就是一个可循环利用的屏障. CyclicBarrier是一个同步辅助类,允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).因 ...