zoukankan      html  css  js  c++  java
  • noip模拟赛

    T1 decode

    解哈夫曼编码

    sol:

    因为哈夫曼编码的性质,我们直接暴力就可以了

    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    inline int read()
    {
        int x = 0,f = 1;char ch = getchar();
        for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
        for(;isdigit(ch);ch = getchar())x = 10 * x + ch - '0';
        return x * f;
    }
    int n;
    string s;
    char ch[10010],ans[10010];
    int len[60];
    map<string,char> hsh;
    string yy,nu;
    int main()
    {
        freopen("decode.in","r",stdin);
        freopen("decode.out","w",stdout);
        n = read();
        for(int i=1;i<=n;i++)
        {
            cin>>s;
            getchar();char cc = getchar();
            hsh[s] = cc;
            //cout<<hsh["0"];
        }
        scanf("%s",ch + 1);
        int m = strlen(ch + 1);
        for(int i=1;i<=m;i++)
        {
            yy = yy + ch[i];
            if(hsh[yy])
            {
                cout<<hsh[yy];
                yy = nu;
            }
        }
    }
    View Code

    T2 build

    有 $n$ 个点 $m$ 条边,每个点补魔花费的时间为 $t_i$

    现在你给第一个点补魔,剩下的点开始补魔当且仅当有一个跟它相邻的点补魔完毕

    求每个点补魔完毕的时间

    sol:

    裸最短路,意会一下

    或者,每个点拆成两个点,补魔前向补魔后连长度为 $t_i$ 的边

    然后连边就是 $u$ 后向 $v$ 前连长度为 $0$ 的边,$u$ 前向 $v$ 后连长度为 $0$ 的边

    每个点的答案就是这个补魔后的这个点的 $dis$

    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    inline int read()
    {
        int x = 0,f = 1;char ch = getchar();
        for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -f;
        for(;isdigit(ch);ch = getchar())x = 10 * x + ch - '0';
        return x * f;
    }
    const int maxn = 100010;
    int n,m,t[maxn];
    int first[maxn],to[maxn << 2],nx[maxn << 2],val[maxn << 2],cnt;
    inline void add(int u,int v)
    {
        to[++cnt] = v;
        nx[cnt] = first[u];
        first[u] = cnt;
        //val[cnt] = w;
    }
    int dis[maxn],vis[maxn];
    #define pa pair<int,int>
    #define mp make_pair
    priority_queue<pa,vector<pa>,greater<pa> > q;
    void spfa()
    {
        memset(dis,127,sizeof(dis));
        dis[1] = 0;q.push(mp(0,1));
        while(!q.empty())
        {
            int now = q.top().second;q.pop();
            if(vis[now])continue;
            vis[now] = 1;
            for(int i=first[now];i;i=nx[i])
            {
                if(dis[to[i]] > dis[now] + t[now])
                {
                    dis[to[i]] = dis[now] + t[now];
                    q.push(mp(dis[to[i]],to[i]));
                }
            }
        }
    }
    signed main()
    {
        freopen("build.in","r",stdin);
        freopen("build.out","w",stdout);
        n = read(),m = read();
        for(int i=1;i<=n;i++)t[i] = read();
        for(int i=1;i<=m;i++)
        {
            int u = read(),v = read();
            add(u,v);add(v,u);
        }
        spfa();
        for(int i=1;i<=n;i++)
            printf("%lld
    ",dis[i] + t[i]);
    }
    View Code

    T3 不方便说

    放在下一篇博客里

    100 + 100 + 70 = 270

    %%% Echo_Hapurubokka

  • 相关阅读:
    23.课程应用接口
    22.课程页面设计
    21.手机接口
    20.云通讯
    19.JWT
    18.权限认证
    解决github下载慢的终极方法
    vs code 配置c/c++环境
    Python 字符编码处理总结
    Python编码
  • 原文地址:https://www.cnblogs.com/Kong-Ruo/p/9924546.html
Copyright © 2011-2022 走看看