A腾讯益智小游戏-矩阵计数
总共(n*m)!
列固定,交换行n!
行固定,交换列m!
一种形式会重复m!*n!
答案是(n*m)!/(n!*m!)
#include
#include
using namespace std;
typedef long long LL;
const LL mod = 998244353;
LL F(LL x) {
LL ans = 1;
for (LL i = 1; i <= x; i++) ans = (ans*i)%mod;
return ans;
}
LL inv(LL x) {
LL b = mod-2,ans = 1;
while(b) {
if (b&1) ans = (ans*x)%mod;
x = x*x%mod;
b>>=1;
}
return ans;
}
int main() {
LL n,m;
cin >> n >> m;
cout << (F(n*m)%mod*inv(F(n)%mod)%mod*inv(F(m)))%mod;
return 0;
}
B. 腾讯益智小游戏—矩形面积交(简单)
n^2枚举
#include
#include
using namespace std;
struct Data {
int x1,x2,y1,y2;
void in() {
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
}
}a[6000];
int calc(Data a,Data b) {
return max((min(a.x2,b.x2)-max(a.x1,b.x1)),0) * max((min(a.y2,b.y2)-max(a.y1,b.y1)),0);
}
void work() {
int n; scanf("%d",&n);
for (int i = 1; i <= n; i++) a[i].in();
for (int i = 1; i <= n; i++) {
int sum = 0;
long long are = 0,tp;
for (int j = 1; j <= n; j++) {
if (j == i) continue;
tp = calc(a[i],a[j]);
if(tp > 0) {
sum++;
are += tp;
}
//cout << i << " " <
留坑