Wannafly挑战赛13 A-B-C

A-zzy的小号

做对这道题的关键在于看懂题,并且要注意题中给出的第四种情况,如果字符a和字符b相同,且字符b又和字符c相同,那么字符a和字符c相同。由此可得,输入的字符串中,大小写的L和大小写的i是可以任意替换的,因此ans * = 4;大小写的O和数字0也可以任意替换,因此ans * = 3;最后如果是字母,再 ans *= 2。

#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
const int N = 1e5,mod = 1e9+7;
char s[N];
int main()
{
    // freopen("in.txt","r",stdin);
    scanf("%s",s);
    long long ans = 1;
    for(int i = 0; s[i]; ++i){
        if(s[i]=='i'||s[i]=='I'||s[i]=='L'||s[i]=='l')
            ans *= 4,ans%=mod;
        else if(s[i]=='o'||s[i]=='O'||s[i]=='0')
            ans *= 3,ans%=mod;
        else if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))
                ans<<= 1,ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

B-Jxc军训

注意!题意让求的是被晒到的概率….而不是不被晒到的QAQ
所以就是问(a^2-m)/(a^2)
分数求模+费马小定理求逆元+快速幂
题中已给出tips: 一个分数p/q在模意义下的值即p*q^(-1)在模意义下的值,X^(p-1)≡1 (mod p)。
所以X^(-1) ≡ X^(p-2)(mod p)

#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll quickPow(ll a,int n)
{
    ll ans = 1;
    ll res = a;
    while(n)
    {
        if(n&1)
            ans = ((ans%mod)*(res%mod))%mod;
        res = ((res%mod)*(res%mod))%mod;
        n >>= 1;
    }
    return ans%mod;
}

int main()
{
    ll a,b;
    scanf("%lld%lld", &a, &b);
    ll bn = quickPow(a*a, mod - 2);//求逆元
    printf("%lld\n", ((a*a-b) *bn) % mod);//记得最后也要mod一下
    return 0;
}

C-zzf的好矩阵

这道题可能就是找规律吧。。膜众巨。。
很多人都可以想到p阶乘,但是还可以通过左右交换和上下交换。
因此最后可推出公式2*(p!)^2

#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main()
{
    ll a,ans=1;
    scanf("%lld", &a);
    for(int i = 1; i <= a; ++i){
        ans *= i;
        ans %= mod;
    }
    ans = 2*(ans*ans)%mod;
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/eternally831143/article/details/79840920