Rikka with Badminton(HDU-6425)(数学+快速幂)

Rikka with Badminton

Problem Description:

In the last semester, Rikka joined the badminton club.

There are n students in the badminton club, some of them have rackets, and some of them have balls. Formally, there are a students have neither rackets nor balls, b students have only rackets, c students have only balls, and d students have both rackets and balls. (a+b+c+d=n)

This week, the club is going to organize students to play badminton. Each student can choose to take part in or not freely. So there are 2n possible registration status.

To play badminton, there must be at least two students who have rackets and at least one students who have balls. So if there aren't enough balls or rackets, the activity will fail.

Now, Rikka wants to calculate the number of the status among all 2n possible registration status which will make the activity fail.


Input:

The first line contains a single number t(1≤t≤103), the number of testcases.

For each testcase, the first line contains four integers a,b,c,d(0≤a,b,c,d≤107,a+b+c+d≥1).


Output:

For each testcase, output a single line with a single integer, the answer modulo 998244353.


Sample Input:

3

1 1 1 1

2 2 2 2

3 4 5 6


Sample Output:

12

84

2904


题意:

这个题的英语真的要吐槽一下,球拍加了复数,但是推示例时发现,居然是一个球拍。。。

我真的服气了。

但是这个题考察关键是分析问题的能力。

题目问:请问有多少种情况是不可以举行的。

其中举行的条件是:必须有两名同学,且这两名同学一定有一副球拍(2只),和一个球。


题解 :

首先,a   :   什么都没有 , b : 只有一个球拍  c:只有一个球 d:有一个球拍和一个球。

不难发现,其实我们可以选择的条件只有三种情况:

1、2b+c

2、b+d

3、2d

但是可能有重复的情况出现,所以分析时一定要仔细。

1、首先是2b+c:

2b=qpow(2,b)-1-b        (  b的人数肯定为:2人或以上),c = qpow(2,c)-1 (C:保证有一个人以上)

其余的是:qpow(2,a)

2、然后有 b+d:

一定要仔细,首先,b:  qpow(2,b)-1,d: d (只选d个人)

其余的是:qpow(2,a+c)

3、最后是 2d:

2d: qpow(2,d)-d-1.

其余的是:qpow(2,a+b+c)

但是这个题有个小细节,但就是这个小细节害我WA多次。

就是mod除时一定要   一个  乘  一个 再模除。

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll qpow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans%mod;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        ll a,b,c,d,n;
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(a==0&&b==0&&c==0&&d==0){
            printf("0\n");
            continue;
        }
        n=a+b+c+d;
        ll D1,D2,D3;
        D1=D2=D3=0;
        ll ans=qpow(2,n);
        if(b>=2&&c>=1)
            D1=(qpow(2,b)-b-1) * (qpow(2,c)-1) %mod * qpow(2,a)%mod;
        if(b>=1&&d>=1)
            D2=(qpow(2,b)-1) * qpow(2,a+c) % mod * d % mod;
        if(d>=2)
            D3=(qpow(2,d)-d-1) * qpow(2,n-d) %mod;
        //printf("%lld %lld %lld %lld\n",D1,D2,D3,ans);
        ans=(ans-D1+mod)%mod;
        ans=(ans-D2+mod)%mod;
        ans=(ans-D3+mod)%mod;
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值