ARC107

A
\(\quad\)简单推式子。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long

const int Mod = 998244353;

signed main()
{
    int a , b , c;
    cin >> a >> b >> c;
    int A = (a + 1) * a / 2;
    int B = (b + 1) * b / 2;
    int C = (c + 1) * c / 2;
    A %= Mod , B %= Mod , C %= Mod;
    int ans = A;
    ans *= B;
    ans %= Mod;
    ans *= C;
    ans %= Mod;
    cout << ans;
    return 0;
}

B
\(\quad\)简单枚举。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long

inline int num(int n , int x)
{
    int fr = x - min(n , x - 1);
    int ne = min(n , x - 1);
    if(fr > ne)
    {
        return 0;
    }
    return ne - fr + 1;
}

signed main()
{
    int n , k;
    cin >> n >> k;
    int ans = 0;
    for(register int i = 2 ; i <= 2 * n ; i++)
    {
        int ab = i;
        int cd = i - k;
        if(cd < 2 || cd > 2 * n)
        {
            continue;
        }
        ans += num(n , ab) * num(n , cd);
    }
    cout << ans;
    return 0;
}

C
\(\quad\)行和列可以分开,并且行列之间的交换可以传递。
\(\quad\)那么就并查集计数然后乘一下就好了。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int long long

const int N = 55;
const int Mod = 998244353;

struct Find
{
    int fa[N];

    inline void clear()
    {
        for(register int i = 0 ; i < N ; i++)
        {
            fa[i] = i;
        }
    }

    inline int find(int x)
    {
        if(x == fa[x])
        {
            return fa[x];
        }
        else
        {
            return fa[x] = find(fa[x]);
        }
    }

    inline void modify(int x , int y)
    {
        int p = find(x) , q = find(y);
        fa[p] = q;
    }
}f1,f2;

int a[N][N];

int s1[N] , s2[N];

int t[N];

inline void build()
{
    int n = 50;
    t[0] = 1;
    for(register int i = 1 ; i <= n ; i++)
    {
        t[i] = t[i - 1] * i;
        t[i] %= Mod;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    int n , k;
    cin >> n >> k;
    for(register int i = 1 ; i <= n ; i++)
    {
        for(register int j = 1 ; j <= n ; j++)
        {
            cin >> a[i][j];
        }
    }
    f1.clear() , f2.clear();
    for(register int x = 1 ; x <= n ; x++)
    {
        for(register int y = 1 ; y <= n ; y++)
        {
            bool xrq = 1;
            for(register int i = 1 ; i <= n ; i++)
            {
                if(a[i][x] + a[i][y] > k)
                {
                    xrq = 0;
                }
            }
            if(xrq == 1)
            {
                f1.modify(x , y);
            }
        }
    }
    for(register int x = 1 ; x <= n ; x++)
    {
        for(register int y = 1 ; y <= n ; y++)
        {
            bool xrq = 1;
            for(register int i = 1 ; i <= n ; i++)
            {
                if(a[x][i] + a[y][i] > k)
                {
                    xrq = 0;
                }
            }
            if(xrq == 1)
            {
                f2.modify(x , y);
            }
        }
    }
    for(register int i = 1 ; i <= n ; i++)
    {
        s1[f1.find(f1.fa[i])]++;
        s2[f2.find(f2.fa[i])]++;
    }
    int ans1 = 1;
    int ans2 = 1;
    build();
    for(register int i = 1 ; i <= n ; i++)
    {
        ans1 *= t[s1[i]];
        ans1 %= Mod;
        ans2 *= t[s2[i]];
        ans2 %= Mod;
    }
    cout << ans1 * ans2 % Mod;
    return 0;
}

ARC107

上一篇:RF定位


下一篇:vue创建登陆窗口并重定向