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. number-progression-network

    T1给定一个 $n$ 位的数字串,要求修改若干位,使得至少包含 $k$ 个相同的数位,最小化代价. Sol 考虑枚举那种数字作为答案,选代价前 $k$ 小的修改成目标数字. 有一部分的数字是必须修改的 ...

  2. postgresql 一些操作

    postgresql 对sql语句敏感的. 所以尽量标准化输入 #############查看版本信息 ############ 1.查看客户端版本 psql --version 1 2.查看服务器端 ...

  3. 我终于搞清楚了和String有关的那点事儿。

    String,是Java中除了基本数据类型以外,最为重要的一个类型了.很多人会认为他比较简单.但是和String有关的面试题有很多,下面我随便找两道面试题,看看你能不能都答对: Q1:String s ...

  4. Try-Catch-Finally代码块中的return

    测试类的原型是这样子的 public class TryCatchFinallyToReturn { public static void main(String[] args) { System.o ...

  5. Prometheus HA详解

    Prometheus 横向扩展 当Exporter或者采集信息需要越来越多时就会考虑高可用,高可用优点不会因为集群中某个节点down而导致Prometheus不可用,可以让算力下沉; 缺点是A-Pro ...

  6. 百度地图API根据地名获取经纬度

    运用了Geocoding API,它包括地址解析和逆地址解析功能. 地址解析是指,由详细到街道的结构化地址得到百度经纬度信息,且支持名胜古迹.标志性建筑名称直接解析返回百度经纬度.例如:“北京市海淀区 ...

  7. Maven Web项目出现org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException错误

    1. 问题描述 初学Maven,新建了一个基于Web骨架的Web项目,jar 包也导好了,作用域也设置正确了,Tomcat也正常运行了,可是就是说编译错误. 2. 问题原因 虽然我配置了Tomcat ...

  8. powerdesigner导出rtf

    报告--reports--新建reports--reports template选择None 从左侧的Available items 拖动 需要导出的item到右侧 右侧的每一个item右键 可以设置 ...

  9. idea 使用maven 下载源码包

    方式1:全量下载源码包 方式二:下载单个源码包 随便找个源码可以看到文件上有download (标识下载源码包) choose sources表示选择那个版本的源码包

  10. onNewIntent

    当Activity不是Standard模式,并且被复用的时候,会触发onNewIntent(Intent intent) 这个方法,一般用来获取新的Intent传递的数据 我们一般会把MainAcit ...