国庆欢乐赛2
Done
OI
Start at: 2024-10-4 14:00
4
hour(s)
Host:
35
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int Mod = 19260817;
int N,M,x,y,e,opt;
struct node{
int a[105][105];
int n,m;
void init(int _n,int _m)
{
n = _n;m=_m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j] = 0;
}
}
}
};
node operator * (node a,node b){
node res;
res.init(a.n,b.m);
for(int i=1;i<=a.n;i++){
for(int j=1;j<=a.n;j++){
for(int k=1;k<=b.m;k++){
res.a[i][j] += (a.a[i][k]*b.a[k][j])%Mod;
}
}
}
return res;
}
node fpow(node a,int x)
{
node res;
res.init(a.n,a.m);
for(int i=1;i<=a.n;i++){
res.a[i][i] = 1;
}
for(;x!=0;x>>=1,a=a*a){
if(x%2==1)res=res*a;
}
return res;
}
int pos(int x,int y)
{
return x+(y-1)*N;
}
void solve(node S)
{
int ans = 0;
int st = pos(x,y);
for(int i=1;i<=N*M;i++){
ans=(ans+S.a[st][i])%Mod;
}
cout<<ans<<endl;
}
void runcar()
{
cin>>N>>M>>x>>y>>e;
node res;
res.init(N*M,N*M);
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
int st = pos(i,j);
for(int k=1;k<=N;k++){
if(k==i)continue;
int en = pos(k,j);
++res.a[st][en];
}
for(int k=1;k<=M;k++){
if(k==j)continue;
int en = pos(i,k);
++res.a[st][en];
}
}
}
node S = fpow(res,e);
solve(S);
}
void runhorse()
{
cin>>N>>M>>x>>y>>e;
int nxt[8][2]={2,1,2,-1,-2,1,-2,-1,1,2,1,-2,-1,2,-1,-2};
node res;
res.init(N*M,N*M);
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
int st = pos(i,j);
for(int k=0;k<8;k++){
int nx = i+nxt[k][0];
int ny = j+nxt[k][1];
if(nx>=1 && nx<=N && ny>=1 && ny<=M){
int en = pos(nx,ny);
++res.a[st][en];
}
}
}
}
node S = fpow(res,e);
solve(S);
}
void runxiang()
{
cin>>N>>M>>x>>y>>e;
int nxt[4][2]={2,2,2,-2,-2,-2,-2,2};
node res;
res.init(N*M,N*M);
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
int st = pos(i,j);
for(int k=0;k<4;k++){
int nx = i+nxt[k][0];
int ny = j+nxt[k][1];
if(nx>=1 && nx<=N && ny>=1 && ny<=M){
int en = pos(nx,ny);
++res.a[st][en];
}
}
}
}
node S = fpow(res,e);
solve(S);
}
signed main()
{
freopen("chess.in","r",stdin);
freopen("chess.out","w",stdout);
int T;
cin>>T;
while(T--){
cin>>opt;
if(opt==0)runcar();
if(opt==1)runhorse();
if(opt==2)runxiang();
}
return 0;
}
Files
Filename | Size | ||
---|---|---|---|
2024暑期CSP-S&NOIP模拟赛第3套题解.pdf | 353.8 KiB | ||
chess.cpp | 2.8 KiB | ||
distance.cpp | 5 KiB | ||
ex_distance2.in | 16.8 MiB | ||
ex_distance2.out | 3.8 MiB | ||
ex_trip2.in | 1.6 MiB | ||
ex_trip2.out | 6 Bytes | ||
ex_xor2.in | 0 Bytes | ||
ex_xor2.out | 0 Bytes | ||
trip.cpp | 1.8 KiB | ||
xor.cpp | 508 Bytes |
- Status
- Done
- Rule
- OI
- Problem
- 4
- Start at
- 2024-10-4 14:00
- End at
- 2024-10-4 18:00
- Duration
- 4 hour(s)
- Host
- Partic.
- 35