• 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

  • 相关阅读:
    Nubia Z5S官方4.4 UI2.0音频Audio部分简单分析(也适用于其它8974/8064机型)以及降低破音出现几率的方法
    import MySQLdb UserWarning
    Visual Studio 2013 Update2
    cocos2d 重写顶点着色语言
    tomcat之组成结构
    4、Android Activity的生命周期 Activity的生命周期
    学习中遇到的c++问题,持续更新
    Android开发之发送邮件功能的实现(源码分享)
    Java 类型, Hibernate 映射类型及 SQL 类型之间的相应关系
    QT内label控件通过opencv显示图像
  • 原文地址:https://www.cnblogs.com/Kong-Ruo/p/9924546.html
Copyright © 2020-2023  润新知