Rikka with Badminton
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 53 Accepted Submission(s): 44
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, bstudents 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
代码:
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll a,b,c,d;
ll ksm(ll a,ll n){
ll ans=1;
while(n){
if(n&1) ans=ans*a%mod;
a=a*a%mod;
n>>=1;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
ll ans=1;
ans=ksm(2,a);
ll w=((ksm(2,b)+ksm(2,c)*(b+d+1)%mod)%mod-(b+1)%mod+mod)%mod;
ans=ans*w%mod;
printf("%lld\n",ans );
}
return 0;
}
RikkawithBadminton问题解析
本文针对RikkawithBadminton问题进行详细分析,探讨了在一个羽毛球俱乐部中,成员拥有球拍和球的不同组合情况下,可能使得活动无法进行的状态数量,并给出了一种高效的算法解决方案。
296

被折叠的 条评论
为什么被折叠?



