,浪费我好久时间,哭了,说我段错误
#include<iostream>
#include<stdlib.h>
#include<stack>
#include<vector>
#include<string>
using namespace std;
int main(){
int T,W,H,P,Q,x,y,a,b;
int res=0;
cin>>T;
while(T--){
cin>>W>>H;
vector<vector<char>> back=vector<vector<char>>(W+1,vector<char>(H+1));
char c;
for(int i=1;i<=H;++i){
for(int j=1;j<=W;++j){
cin>>c;
back[i][j]=c;
}
}
cin>>P>>Q;
vector<vector<char>> image=vector<vector<char>>(P,vector<char>(Q));
for(int i=0;i<Q;++i){
for(int j=0;j<P;++j){
cin>>c;
image[i][j]=c;
}
}
cin>>x>>y>>a>>b;
//图像初始化
vector<vector<char>> running=back;
for(int i=0;i<Q;++i){
for(int j=0;j<P;++j){
if(i+x>0&&i+x<=H&&j+y>0&&j+y<=W){
running[i+x][j+y]=image[i][j];
}
}
}
int temp=0;
for(int i=1;i<=H;++i){
for(int j=1;j<=W;++j){
if(back[i][j]!=running[i][j])
temp++;
}
}
int move_count=0;
//vector<vector<char>> old_Running=vector<vector<char>>(W+1,vector<char>(H+1));
vector<vector<char>> old_Running=running;
//开始移动
while(temp){
running=back;
res+=temp;
temp=0;
move_count++;
for(int i=0;i<Q;++i){
for(int j=0;j<P;++j){
if(i+x+move_count*b>0&&i+x+move_count*b<=H&&j+y+move_count*a>0&&j+y+move_count*a<=W){
running[i+x+move_count*b][j+y+move_count*a]=image[i][j];
}
}
}
for(int i=1;i<=H;++i){
for(int j=1;j<=W;++j){
if(old_Running[i][j]!=running[i][j])
temp++;
}
}
old_Running=running;
}
cout<<res<<endl;
res=0;
}
system("pause");
return 0;
}
全部评论
(1) 回帖