矩阵翻转WA0分样例已过

#include<bits/stdc++.h>
using namespace std;
int n,m,q,xa,ya,xb,yb,a[501][501],cf[501][501];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			cf[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1];
		}
	}
	for(int i=1;i<=q;i++){
		cin>>xa>>ya>>xb>>yb;
		cf[xa][ya]+=1;
		cf[xb+1][ya]-=1;
		cf[xa][yb+1]-=1;
		cf[xb+1][yb+1]+=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			a[i][j]=(a[i-1][j]+a[i][j-1]-a[i-1][j-1]+cf[i][j])%2;
			cout<<abs(a[i][j])<<" ";
		}
		cout<<endl;
	}
	return 0;
}
1 个赞

自己构造样例,或者下载样例

1 个赞

@应梓轩

        cf[xa][ya]+=1;
		cf[xb+1][ya]-=1;
		cf[xa][yb+1]-=1;
		cf[xb+1][yb+1]+=1;
应是:
        cf[xa][ya]+=1;
		cf[xa][yb+1]-=1;
		cf[xb+1][ya]-=1;
		cf[xb+1][yb+1]+=1;
1 个赞

还有: a[i][j]=(a[i-1][j]+a[i][j-1]-a[i-1][j-1]+cf[i][j])%2;
应是:cf[i][j]=(cf[i-1][j]+cf[i][j-1]-cf[i-1][j-1]+cf[i][j])%2;

1 个赞