B交换数字
题目:
思路:我们可以知道,a*b% mod = (a%mod) * (b%mod)
代码:
void solve(){int n;cin >> n;string a, b;cin >> a >> b;for(int i = 0;i < n;i ++)if(a[i] > b[i])swap(a[i], b[i]);int num1 = 0, num2 = 0;for(int i = 0;i < n;i ++){num1 = (num1 * 10 + (a[i] - '0')) % mod;num2 = (num2 * 10 + (b[i] - '0')) % mod;}cout << num1 * num2 % mod;
}
C老虎机
题目:
思路:我们可以算出总共的方案为m * m * m,然后三个图相同的方案为m,三个图都不相同的方案为m * (m - 1) * (m - 2)。然后按照要求求即可。
代码:
const int mod = 998244353;int qmi(int a, int k, int p)
{__int128 res = 1;while (k){if (k & 1)res = (__int128)res * a % p;k >>= 1;a = (__int128)a * a % p;}return res;
}void solve(){int m, a, b, c;cin >> m >> a >> b >> c;int mu = m * m * m;int ans1 = m * (m - 1) * (m - 2) % mod, ans3 = m;int ans2 = (mu - ans1 - ans3) % mod;int u = (qmi(mu, mod - 2, mod) + mod) % mod;cout << ((((a * ans1 + b * ans2 + c * ans3) % mod) * u ) % mod + mod) % mod << endl;
}
D幻兽帕鲁
题目:
思路:我们可以想出,如果站在[mid+1,r]中,那么是当前位为奇数,在[l,mid]为偶数,那么我们可以正着操作输入的x,如果但前x大于mid,那么答案当前位位1,否则为0.
代码:
void solve(){read(n);read(m);ll up = (1LL << n);rep(ss,1,m){ll x,y = up;read(x);x++;ll ans = 0;ll sum = 0;rep(i,0,n - 1){y /= 2;if(x > y){ans |= (1LL << i);x -= y;}else{}}printf("%lld\n",ans);}
}