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=0,f=0; char ch=0;
    while(!isdigit(ch)) {f|=ch==‘-‘;ch=getchar();}
    while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int maxn=1005;
const int maxm=5e5+5;
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=1; i<=n; i++)
        dist[i]=inf,vis[i]=0;
    dist[s]=0;
    que.push(node2(0,s));
    while(!que.empty())
    {
        int u=que.top().id;
        que.pop();
        if(vis[u]) continue;
        vis[u]=1;
        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=1; i<=n; ++i)
        vis[i]=0;
    que.push(node2(0,s));
    while(!que.empty()){
        node2 now=que.top();que.pop();
        int nid=now.id,nw=now.w;
        if(vis[nid]) continue;
        vis[nid]=1;
        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=0;
        ans1=ans2=0;
        for(int i=1;i<=n;++i)
            head[i]=0,isk[i]=0;
        for(int i=1;i<=k;++i)
            isk[read()]=1;
        for(int i=1;i<=m;++i){
            int u=read(),v=read(),w=read();
            adde(u,v,w);
            adde(v,u,w);
        }
        dijkstra(s);
        for(int i=1;i<=n;++i)
            ans1=max(ans1,dist[i]);
        for(int i=1;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 0;
}



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[105];

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=1;i<=Q;++i){
            scanf("%d",&query[i].q);
            query[i].id=i;
        }
        sort(query+1,query+1+Q,cmp1);
        queue<int> que;
        for(int i=n;i>=1;--i){
            if(!que.empty()){
                for(int j=1;j<=m;++j){
                    int tmp=que.front();que.pop();
                    que.push(tmp);
                }
            }
            que.push(i);
        }
        int cnt=1;
        for(int i=n;i>=1;--i){
            int tmp=que.front();que.pop();
            if(i==query[cnt].q)
                query[cnt++].ans=tmp;
            if(cnt>Q) break;
        }
        sort(query+1,query+1+Q,cmp2);
        for(int i=1;i<=Q;++i)
            printf("%d\n",query[i].ans);
    }
    return 0;
}



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==1) printf("18000\n");
        else printf("0\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/FrankChen831X/p/11491063.html

时间: 2024-08-01 00:02:07

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

2019ICPC南昌网络赛总结

打的很崩的一场比赛.上来签到题我就wa了一发,感觉在梦游.然后我开了H题,队友开B题,f(n)=3f(n-1)+2f(n)傻子都知道矩阵快速幂,但是1e7的强制在线必须把logn优化,然后试图打表寻找循环节,也没找到,然后对矩阵进行研究,看着矩阵快速幂 $\left(\begin{matrix}3 & 2 \\1 & 0 \end{matrix}\right)$这个矩阵长得挺好看的,试图寻找O(1)计算出 $\left(\begin{matrix}3 & 2 \\1 & 0

2019 ICPC 南昌网络赛

2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 // 史上排名最高一次,开场不到两小时队友各A一题加水题共四题,排名瞬间升至三四十名 // 然后后三小时就自闭了,一题都没有突破...最后排名211 hhhh ? ? B. Fire-Fighting Hero 题意 队友做的,待补. ? AC代码 #include<cstdio> #includ

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

ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询问子区间中某个值域的数的个数,连续的相同数字只记为一个.(即统计数字段的个数) 2 L R x y 数据范围: 1 ≤ n,m ≤ 2×10^5 1 ≤ a[i] ≤ n 解题思路: 连续重复的数字只记一次.所以考虑将每个数字段除第一个出现外的数字都删去(记为0).在读入操作的时候暴力模拟,同时维护

2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a square matrix of n * nn?n, each lattice has its value (nn must be odd), and the center value is n * nn?n. Its spiral decline along the center of the squar

19南昌网络赛L

校赛打杂没施展开. 题意:一开始给你一颗 (0,0)到(0,l)的树. 这棵树每一年会长出来三个幼芽(雾),长度均为l/4,方向分别是左转60,右转60,和不变. 年份<=14 考虑3^14直接暴力存边然后考虑每条边贡献.发现奇难无比. 考虑剪枝. 注意到如果一根树枝的被砍掉了那么他所有的孩子全都不算贡献了.妙啊!变成傻逼题. 抄一下板子. 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef double db; 4 c

2019南昌网络赛-I(单调栈+线段树)

题目链接:https://nanti.jisuanke.com/t/38228 题意:定义一段区间的值为该区间的和×该区间的最小值,求给定数组的最大的区间值. 思路:比赛时还不会线段树,和队友在这题上弄了3小时,思路大体都是对的,但就是没法实现.这几天恶补线段树. 首先可以利用单调栈来查找满足a[i]为最小值的最大区间L[i]~R[i].然后利用线段树求一个段的和sum.最小前缀lsum和最小后缀rsum.然后遍历a[i]: a[i]>0:最优为sum(L[i],R[i])*a[i] a[i]<

2019年ICPC南昌网络赛 J. Distance on the tree 树链剖分+主席树

边权转点权,每次遍历到下一个点,把走个这条边的权值加入主席树中即可. #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; const int maxx = 2e5+10; struct node{ int l,r,cnt; }tree[maxx*40]; int head[maxx],rk[maxx],siz[maxx

2019icpc银川网络赛-A Maximum(思维)

题目链接:https://nanti.jisuanke.com/t/41285 题意:维护一个栈,支持入栈和出栈操作,并计算每次操作后的栈中最大值,得到最终结果. 思路: 外面吵得风生水起,我校平静地在打比赛,丝毫不知道这次比赛的题目就是把2018银川邀请赛的题照搬过来了QAQ,主办方真牛逼.. 这题真的是,我和hxc轮流做这道题,被坑惨了,一直以为使用数据结构来做,没想到点上去.思维题,每次保证栈顶为栈中最大元素.如果当前入栈的元素为x,当前栈顶元素为y,如果x>=y,这个没问题,直接入栈就行

2019icpc南京网络赛 A 主席树

题意 给一个\(n\times n\)的螺旋矩阵,给出其中的\(m\)个点的值分别为各个点上数字的数位之和,给出\(q\)个询问,每次询问从\((x1,y1)\)到\((x2,y2)\)的子矩阵的和. 分析 用官方题解的方法\(O(1)\)推出点\((x,y)\)上的值,将这\(m\)个点按\(x\)排序后依次按\(y\)建主席树,查询时找到对应的\(x1\)和\(x2\)的历史版本,查询\(y1\)到\(y2\)的权值和就行了,\((query(y1,y2,1,n,rt[l],rt[r]))\