2019icpc南昌网络赛
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南昌网络赛的更多相关文章
- 线段树+单调栈+前缀和--2019icpc南昌网络赛I
线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...
- 2019icpc南昌网络赛_I_Yukino With Subinterval
题意 给定一个序列,两种操作,单点修改,询问区间\([l,r]\)值域在\([x,y]\)范围内的连续段个数. 分析 原数组为\(a\),构造一个新的数组\(b\),\(b[i]=(a[i]==a[i ...
- 2019ICPC南昌网络赛总结
打的很崩的一场比赛.上来签到题我就wa了一发,感觉在梦游.然后我开了H题,队友开B题,f(n)=3f(n-1)+2f(n)傻子都知道矩阵快速幂,但是1e7的强制在线必须把logn优化,然后试图打表寻找 ...
- 2019ICPC南昌网络赛C Hello 2019
题意:给出一个字符串,每次询问一个区间[l,r],求使得这个区间含有9102但不含有8102最少要删掉几个字符 首先我们考虑将串反转,这样就变成了含有2019但不含有2018的问题了 我们构建一个状态 ...
- 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 ...
- 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)
题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval
ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...
- 南昌网络赛C.Angry FFF Party
南昌网络赛C.Angry FFF Party Describe In ACM labs, there are only few members who have girlfriends. And th ...
随机推荐
- Hdu Can you find it?(二分答案)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others) P ...
- C语言学习笔记1-数据类型和标识符
http://blog.csdn.net/jadeshu/article/details/50751901 1.数据类型 ---1.1基本类型 --------------数值型(short(2) i ...
- Dubbo——配置
一.配置原则 JVM 启动 -D 参数优先,这样可以使用户在部署和启动时进行参数重写,比如在启动时需改变协议的端口. XML 次之,如果在 XML 中有配置,则 dubbo.properties 中的 ...
- python 获取远程设备ip地址
python2.7 #!/usr/bin/env python # Python Network Programming Cookbook -- Chapter - # This program is ...
- ICEM-extrude功能画圆柱绕流网格【转载】
转载自:http://blog.csdn.net/lgw19910426/article/details/26401517 首先画网格大体顺序为点-->线-->面-->单元体. 第一 ...
- JAVA基础知识|Socket
一.什么是Socket? Socket本身并不是协议,是一套完成TCP.UDP协议的调用接口(API),通过socket我们才能使用TCP/IP协议(JAVA基础知识|TCP/IP协议).Socket ...
- 攻防世界RE1 writeup
解题过程 将题目给出的exe文件拖入ida中,查看main函数. 分析函数的逻辑,发现用户需要输出一个字符串,存储到变量v9中.如果v9的值与v5的值相等则会打印unk_413e90中的值,否则打印a ...
- mybatis+mysql批量插入和批量更新、存在及更新
mybatis+mysql批量插入和批量更新 一.批量插入 批量插入数据使用的sql语句是: insert into table (字段一,字段二,字段三) values(xx,xx,xx),(oo, ...
- 浅述不同版本ios系统有什么特点 ios 1 -ios 12
版本记录 版本号 时间 V2.0 2019.08.20 前言 到目前为止,ios的版本已经发到了ios11的测试版,今年正式版马上就会出来,ios发布了这么多的版本,到底每个版本都有什么显著的特点?用 ...
- form表单无刷新提交
Ajax最大的特点就是可以不刷新页面而实现数据的通信及更改页面信息.那么用AJAX进行后台通信传递字符串还是可以的,遇到上传文件该怎么办呢?基于安全考虑,JS是不能直接进行文件操作的,只好用原始的fr ...