2018 Multi-University Training Contest 9 杭电多校第九场

1001 Rikka with Nash Equilibrium

可以dp,也可以找规律

#include<bits/stdc++.h>
#define N 100005
#define P pair<int,int>
using namespace std;
typedef long long ll;
const int M=1e9+7;
const int inf=1e9+7;

int main()
{
    int t,n,m,mod;
    for(scanf("%d",&t);t;t--)
    {
        scanf("%d%d%d",&n,&m,&mod);
        int ans=1;
        for(int i=n+m;i<=n*m;i++)
            ans=1LL*ans*i%mod;
        for(int i=1;i<n;i++)
            ans=1LL*ans*i%mod;
        for(int i=1;i<m;i++)
            ans=1LL*ans*i%mod;
        printf("%lld\n",1LL*ans*n*m%mod);
    }
    return 0;
}

 

1002 Rikka with Seam

#include<bits/stdc++.h>
#define N 2003
#define P pair<int,int>
using namespace std;
typedef long long ll;
const int M=998244353;
const int inf=1e9+7;
char s[N][N];
ll tot[N][N],same[N][N];
ll pre_tot[N],pre_same[N];
int main()
{
    int t,n,m,k;
    for(scanf("%d",&t);t;t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=n;i++)
            scanf("%s",s[i]+1);
        for(int i=1;i<=m;i++){
            tot[1][i]=1;
            same[1][i]=s[1][i]==s[1][i-1];
        }
        for(int i=2;i<=n;i++){
            pre_tot[0]=pre_same[0]=0;
            for (int j=1;j<=m;j++){
                pre_tot[j]=(pre_tot[j-1]+tot[i-1][j])%M;
                pre_same[j]=(pre_same[j-1]+same[i-1][j])%M;
            }
            for(int j=1;j<=m;j++){
                int l=max(1,j-k),r=min(m,j+k);
                tot[i][j]=(pre_tot[r]-pre_tot[l-1]-pre_same[r]+pre_same[l])%M;
                r=min(m,j+k-1);
                if(s[i][j]!=s[i][j-1])same[i][j]=0;
                else same[i][j]=(pre_tot[r]-pre_tot[l-1]-pre_same[r]+pre_same[l])%M;
            }
        }
        ll ans=0;
        for(int i=1;i<=m;i++)
            ans=(ans+tot[n][i]-same[n][i])%M;
        printf("%lld\n",(ans+M)%M);
    }
    return 0;
}

 

1004 Rikka with Stone-Paper-Scissors

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ll T;
    scanf("%lld",&T);
    while(T--)
    {
        ll a,b,c;
        ll A,B,C;
        scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&A,&B,&C);
        ll ans=A*(c-b)+B*(a-c)+C*(b-a);
        ll sum=a+b+c;
        ll g=__gcd(ans,sum);
        ans/=abs(g);
        sum/=abs(g);
        if(sum==1)printf("%lld\n",ans);
        else printf("%lld/%lld\n",ans,sum);
    }
}

 

1011 Rikka with Badminton

 

#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
LL fac[10000000 + 10];
LL A[10000007];
LL qpow(LL a, LL b)
{
    LL ans = 1;
    a %= MOD;
    while (b)
    {
        if (b & 1)
        {
            ans = ans * a % MOD;
            b--;
        }
        b >>= 1;
        a = a * a % MOD;
    }
    return ans;
}
LL C(LL n, LL m)
{
    if (n < m) return 0;
    return fac[n] *
        //qpow(fac[m] * fac[n - m] % MOD, MOD - 2) % MOD;
        A[m] % MOD*A[n - m] % MOD;
}
void Init()
{
    A[1] = 1;
    for (int i = 2; i <= 10000000 + 10; i++)
    {
        A[i] = (MOD - (MOD / i))*A[MOD%i] % MOD;
    }
    for (int i = 1; i <= 10000000 + 10; i++)
    {
        A[i] = A[i - 1] * A[i] % MOD;
    }
    fac[0] = 1;
    for (int i = 1; i < 10000000 + 5; i++)
        fac[i] = (fac[i - 1] * i) % MOD;
}
int main()
{
    int T;
    scanf("%d", &T);
    Init();
    while (T--)
    {
        LL a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        LL ans = 0;
        if (b >= 2 && c >= 1)
        {
            //ans += C(b, 2)*c;
            ans += (qpow(2LL, b) - b - 1)*(qpow(2LL, c) - 1);
            ans %= MOD;
        }
        if (b >= 1 && d >= 1)
        {
            //ans += d * b*2^c;
            ans += (qpow(2LL, b) - 1)*d%MOD*qpow(2LL, c);
            ans %= MOD;
        }
        if (d >= 2)
        {
            ans += (qpow(2LL, d) - 1 - d)* qpow(2LL, b + c);
            ans %= MOD;
        }
        ans = ans + MOD % MOD;
        ans *= qpow(2LL, a);
        ans %= MOD;
        ans = qpow(2LL, a + b + c + d) - ans + MOD;
        ans %= MOD;
        printf("%lld\n", ans);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值