题解
对某一片区域+1-1等操作,二维差分,注意每一维的含义和往下一维转移的细节就行了
code
#include<bits/stdc++.h>
using namespace std;
int wave1[3005]={0},wave2[3005]={0};
int sum[3005]={0};
string s[3005];
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i];
s[i]=' '+s[i];
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
sum[j]=sum[j-1]+wave1[j]-wave2[j];
}
for(int j=1;j<=n;j++)
{
if(sum[j]%2!=s[i][j]-'0')
{
ans++;
wave1[j]++;
wave2[j+1]++;
}
}
wave1[1]+=wave1[2];
for(int j=2;j<n;j++) wave1[j]=wave1[j+1];
wave1[n]=0;
for(int j=n;j>1;j--) wave2[j]=wave2[j-1];
wave2[1]=0;
}
cout<<ans<<"\n";
for(int i=1;i<=n+1;i++)//n+1主要是为了清空wave2
{
wave1[i]=0;
wave2[i]=0;
}
}
return 0;
}
标签:Matrix,int,cin,3005,Cascade,wave2,tie
From: https://www.cnblogs.com/pure4knowledge/p/18248473