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. Oracle 审计 部署监控 user DML操作

    1.移动audit表及索引到dbadmin表空间 alter table aud$ move tablespace DBADMIN;alter table AUDIT$ move tablespace ...

  2. Crystal Report水晶报表碰到的一些纠结问题

    1.插入PNG文件时,透明的背景会变成黑色.试了矢量图WMF文件,是可以正常显示的,不过毕竟得到矢量图比较困难.   后来找到个方法,就是把JPG图片放在子报表里,调整子报表在父报表的位置并且保持JP ...

  3. java+上传文件夹

    最近在学习百度的开源上传组件WebUploader,写了一些示例以记录.WebUploader的缺点是没有一个比较好的现成的界面,这个界面需要自己去实现.自由度高了一些. WebUploader是由B ...

  4. 【概率论】2-1:条件概率(Conditional Probability)

    title: [概率论]2-1:条件概率(Conditional Probability) categories: Mathematic Probability keywords: Condition ...

  5. open, create, close

    1.open 系统调用 说明: 调用open函数打开或者创建一个文件.函数定义如下:  #include <fcntl.h> int open(const char *pathname, ...

  6. sql语句查询出的某字段内容截取

    select  LEFT(context,LENGTH(context)-1) context    from table; (效果: 1,2,3, 查询出: 1,2,3 )

  7. 使用 Linux Mint 作为主要操作系统的一些个人常用软件

    本篇文章讲一下一些 Linux 上的应用,多数为日常生活娱乐用的软件,同时也会讲一点开发工具,对于有兴趣继续研究 Linux 的可以参考一下. 目录 软件的安装方式 1.Software Manage ...

  8. 牛顿法与拟牛顿法(四) BFGS 算法

    转自 https://blog.csdn.net/itplus/article/details/21897443

  9. vue cli 安装element-ui

    1.安装elment-ui --save 参数:上线打包 MacBookPro:vue_test zhangxm$ npm install element-ui axios --save npm WA ...

  10. 【Linux】安装 PostgreSQL

    参考: CSDN1:https://blog.csdn.net/ctwy291314/article/details/79900074 1.进入 PostgreSQL 官网的下载地址, 2.选择下面的 ...