• The 2016 ACM-ICPC Asia Shenyang Regional Contest


    A. Thickest Burger

    大数 × 2 + 小数

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    int T;
    int A,B;
    int main()
    {
        scanf("%d",&T);
        for(int t=1; t<=T; t++)
        {
            scanf("%d%d",&A,&B);
            if(A<B) swap(A,B);
            printf("%d
    ",A*2+B);
        }
        return 0;
    }
    

      

    B. Relative atomic mass

    给定一个分子式,只包含 H C O 三种,求相对分子质量。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn=15;
    
    char s[maxn];
    int T, ans = 0;
    int main()
    {
        scanf("%d",&T);
        for(int t=1; t<=T; t++)
        {
            ans=0;
            scanf("%s",s);
            int n=strlen(s);
            for(int i=0; i<n; i++)
            {
                if(s[i]=='H') ans++;
                if(s[i]=='C') ans+=12;
                if(s[i]=='O') ans+=16;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    

      

    C. Recursive sequence

    矩阵快速幂

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long LL;
    const LL MOD = 2147493647;
    int a, b;
    LL C[7][7];
    
    void mut(LL A[][7], LL B[][7]) {
        memset(C, 0, sizeof(C));
        for(int i = 0; i < 7; ++i)
            for(int j = 0; j < 7; ++j)
                for(int k = 0; k < 7; ++k)
                    C[i][j] = ( C[i][j] + A[i][k] * B[k][j] ) % MOD;
        memcpy(A, C, sizeof(C));
    }
    
    LL qpow(int n) {
        LL aa[7][7] = {{1,2,1,0,0,0,0},{1,0,0,0,0,0,0},{0,0,1,4,6,4,1},{0,0,0,1,3,3,1},{0,0,0,0,1,2,1},{0,0,0,0,0,1,1},{0,0,0,0,0,0,1}};
        LL ans[7][7] = {{1,0,0,0,0,0,0},{0,1,0,0,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,1,0,0},{0,0,0,0,0,1,0},{0,0,0,0,0,0,1}};
        while(n) {
            if(n&1) mut(ans, aa);
            mut(aa,aa);
            n>>=1;
        }
        LL res = ans[0][0] * b % MOD + ans[0][1] * a % MOD + ans[0][2] * 3 * 3 * 3 * 3 % MOD;
           res = res + ans[0][3] * 3 * 3 * 3 % MOD + ans[0][4] * 3 * 3 % MOD + ans[0][5] * 3 % MOD;
           res = ( res + ans[0][6] ) % MOD;
        return res;
    }
    
    int main() {
        int T;
        scanf("%d", &T);
        while(T--) {
            int n;
            scanf("%d%d%d", &n, &a, &b);
            if(n == 1) {
                printf("%d
    ",a);
                continue;
            }
            LL ans = qpow(n-2);
            printf("%lld
    ", ans);
        }
        return 0;
    }
    

      

    D. Winning an Auction

    博弈

    E. Counting Cliques

    爆搜。vector[i] 记录与 i 有边且编号大于的点。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    using namespace std;
    const int maxn = 100 + 10;
    const int maxm = 1000 + 100;
    
    int n, m, k;
    vector<int> v[maxn];
    int from[maxm], to[maxm];
    int G[maxn][maxn];
    int d[maxn], node[maxn];
    int tot, ans;
    
    void DFS(int x, int start)
    {
        if (tot == k) { ++ans; return; }
    
        int sz = v[x].size();
        for (int i = start; i < sz; i++)
        {
            int flag = 0;
            for (int j = 2; j <= tot; j++)
            if (!G[ node[j] ][ v[x][i] ]) { flag = 1; break; }
    
            if (flag) continue;
    
            node[++tot] = v[x][i], DFS(x, i+1), --tot;
        }
    }
    
    int main()
    {
        int t;
        scanf("%d", &t);
        for (int ca = 1; ca <= t; ca++)
        {
            memset(d, 0, sizeof(d));
            for (int i = 1; i <= n; i++)
            {
                for (int j = i+1; j <= n; j++) G[i][j] = G[j][i] = 0;
                v[i].clear();
            }
    
            scanf("%d%d%d", &n, &m, &k);
            for (int i = 1; i <= m; i++)
            {
                scanf("%d%d", &from[i], &to[i]);
                d[ from[i] ]++, d[ to[i] ]++;
            }
    
            for (int i = 1; i <= m; i++)
                if (d[ from[i] ] >= k-1 && d[ to[i] ] >= k-1)
                {
                    if (from[i] < to[i]) v[ from[i] ].push_back(to[i]);
                        else v[ to[i] ].push_back(from[i]);
                    G[ from[i] ][ to[i] ] = G[ to[i] ][ from[i] ] = 1;
                }
    
            ans = 0;
            for (int i = 1; i <= n; i++)
            {
                tot = 1, node[1] = i;
                DFS(i, 0);
            }
    
            printf("%d
    ", ans);
        }
    }
    

      

    F. Similar Rotations

    G. Do not pour out

    H. Guessing the Dice Roll

    I. The Elder

    J. Query on a graph

    K. New Signal Decomposition

    L. A Random Turn Connection Game

    M. Subsequence

  • 相关阅读:
    JavaSE-方法覆盖的注意事项
    underscore.js源码研究(4)
    underscore.js源码研究(3)
    移动端font-size适配方案
    控制台引入想要的库
    页面布局与编写(续3)
    underscore.js源码研究(2)
    全屏使用swiper.js过程中遇到的坑
    模块加载
    underscore.js源码研究(1)
  • 原文地址:https://www.cnblogs.com/ruthank/p/9745797.html
Copyright © 2020-2023  润新知