jktm_666 @ 2024-10-27 15:34:02
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001];
int b[1001][1001],num[6];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int n,m,k,x,y,d;
cin>>n>>m>>k>>x>>y>>d;
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
cin>>a[j][k];
}
}
b[x][y]=1;
for(int j=1;j<=k;j++){
if(d==0){
y++;
if(y>m||a[x][y]=='x'){
y--;
d++;
d%=4;
continue;
}
b[x][y]++;
}
if(d==1){
x++;
if(x>n||a[x][y]=='x'){
x--;
d++;
d%=4;
continue;
}
b[x][y]++;
}
if(d==2){
y--;
if(y==0||a[x][y]=='x'){
y++;
d++;
d%=4;
continue;
}
b[x][y]++;
}
if(d==3){
x--;
if(x==0||a[x][y]=='x'){
x++;
d++;
d%=4;
continue;
}
b[x][y]++;
}
}
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
if(b[j][k]>0){
num[i]++;
}
}
}
}
for(int i=1;i<=n;i++){
cout<<num[i]<<endl;
}
return 0;
}
by lty2023 @ 2024-10-27 15:50:10
#include<bits/stdc++.h>
using namespace std;
void ans(){
int a,b,c;
bool d[1010][1010],dd[1010][1010];
cin>>a>>b>>c;
int x,y,h;
cin>>x>>y>>h;
for(int i=1;i<=a;i++){
for(int j=1;j<=b;j++){
char ch;
cin>>ch;
if(ch=='x'){
d[i][j]=1;
}
else{
d[i][j]=0;
}
dd[i][j]=0;
}
}
for(int i=0;i<c;i++){
dd[x][y]=1;
int x2,y2;
if(h==0){
x2=x;
y2=y+1;
}
if(h==1){
x2=x+1;
y2=y;
}
if(h==2){
x2=x;
y2=y-1;
}
if(h==3){
x2=x-1;
y2=y;
}
if(!d[x2][y2]&&x2<=a&&y2<=b&&x2>=1&&y2>=1){
x=x2;
y=y2;
}
else{
h++;
if(h==4){
h=0;
}
}
}
dd[x][y]=1;
int sum=0;
for(int i=1;i<=a;i++){
for(int j=1;j<=b;j++){
if(dd[i][j]){
sum++;
}
}
}
cout<<sum<<endl;
}
int main(){
int T;
cin>>T;
for(int i=0;i<T;i++){
ans();
}
}
求关注
by fangjianan @ 2024-10-27 15:50:38
每组数据处理完之后b数组没有归零
by lty2023 @ 2024-10-27 15:50:40
别问我为什么不在你的上改,问就是看不懂