zoukankan      html  css  js  c++  java
  • Codeforces Round #564 (Div. 2)

    这个div2 的AB 还是很简单的,C题思路简单,但是这个模拟不好写啊。

    A. Nauuo and Votes

    这个题目的意思就是说让你判断z是不是会影响x,y进行大小的比较。

    这个很简单。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string.h>
    #include <queue>
    #include  <cmath>
    using namespace std;
    
    int main()
    {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        if (z > 0 && abs(x - y) <= z) printf("?
    ");
        else if (x > y) printf("+
    ");
        else if (y > x) printf("-
    ");
        else if (x == y) printf("0
    ");
        return 0;
    }
    A

    B. Nauuo and Chess

    这个B题也很简单,看题就应该会了吧。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include  <cmath>
    using namespace std;
    
    int main()
    {
        int n;
        scanf("%d", &n);
        int m = ((n - 1) % 2 == 0 ? (n - 1) / 2 : ((n - 1) / 2 + 1)) + 1;
        printf("%d
    ", m);
        printf("1 1
    ");
        n--;
        int r = 1, c = 1;
        while(n--)
        {
            if (r >= m) c++;
            else r++;
            printf("%d %d
    ", r, c);
        }
    }
    B

    C. Nauuo and Cards

    模拟题,挺麻烦的。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include  <cmath>
    using namespace std;
    const int maxn = 2e5 + 10;
    int a[maxn],b[maxn];
    int num[maxn];
    int main()
    {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for(int i=1;i<=n;i++)
        {
            scanf("%d", &b[i]);
            num[b[i]] = i;
        }
        bool flag = false;
        int tot = b[n];
        while (tot != 1 && num[tot] == num[tot - 1] + 1) tot--;
        if(tot==1)
        {
            //printf("www %d
    ", b[n]);
            for(int i=b[n]+1;i<=n;i++)
            {
            //    printf("i=%d %d
    ", i, num[i]);
                if (num[i] > i - b[n] - 1) {
                    flag = true;
                    break;
                }
            }
            if(!flag)
            {
                printf("%d
    ", n - b[n]);
                return 0;
            }
        }
        int ans = n, mark = 0;
        int cnt = num[1];
        for(int i=1;i<=n;i++)
        {
            if (num[i] < cnt) cnt++;
            else while (num[i] >= cnt) cnt++;
            //printf("num[%d]=%d cnt=%d
    ", i, num[i], cnt);
            if(cnt>=n)
            {
                mark = i;
                break;
            }
        }
        ans += (n - mark) + (cnt - n);
        printf("%d
    ", ans);
        return 0;
    }
    C

    D. Nauuo and Circle

    这个题目是一个思维题,还是有点难想的思维题,

    我看的题解 https://www.cnblogs.com/violet-acmer/p/10991346.html

    这个博客讲的听清楚的。

    这个是一棵树,根节点设为1,然后它的子节点数量为x,排列的方案数是不是为 x!

    然后再从子节点里面找节点,每一个根节点的子节点都会分配一块区域,这个相当于另外一个根节点往后面找子节点的排列。

    其实没有想象之中的那么难,容易理解但是没那么好想。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #include <iostream>
    #define inf 0x3f3f3f3f
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5 + 10;
    const int mod = 998244353;
    ll f[maxn], dp[maxn];
    vector<int>G[maxn];
    vector<int>son[maxn];
    
    void dfs(int u,int pre)
    {
        for(int i=0;i<G[u].size();i++)
        {
            int v = G[u][i];
            if (v == pre) continue;
            dfs(v, u);
            son[u].push_back(v);
        }
        int k = son[u].size() + (u == 1 ? 0 : 1);
        dp[u] = f[k];
        for(int i=0;i<son[u].size();i++)
        {
            int v = son[u][i];
            dp[u] = dp[u] %mod * dp[v] % mod;
            dp[u] %= mod;
        }
    }
    
    ll solve(int n)
    {
        f[0] = 1;
        for (int i = 1; i <= n; i++) f[i] = (i*f[i - 1] % mod);
        dfs(1, 0);
        return (dp[1] % mod*n%mod) % mod;
    }
    
    int main()
    {
        int n;
        scanf("%d", &n);
        for(int i=1;i<n;i++)
        {
            int u, v;
            scanf("%d%d", &u, &v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        ll ans = solve(n);
        printf("%I64d
    ", ans%mod);
        return 0;
    }
    D
  • 相关阅读:
    NUI四种提交数据方式c
    除Hadoop大数据技术外,还需了解的九大技术
    svn提交报错:svn: Aborting commit:XXXXXremains in conflict
    普元部署多个应用的方法(适用EOS6.5以上版本,且无需governor中添加应用)
    C#根据html生成PDF
    判断一个数值是否在一个逗号分隔的字符串中
    判断网站地址是否是http开头
    Date.prototype.format
    C#实现XML与DataTable互转
    C#读取Excel表格数据到DataGridView中和导出DataGridView中的数据到Excel
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/11004330.html
Copyright © 2011-2022 走看看