SerenityWay @ 2024-11-05 21:10:41
考试时写的,当时以为可以AC,结果只得了70。WA on #5 #7 #10
代码:
#include <bits/stdc++.h>
using namespace std;
char c[1005][1005]={'x'};
int main(){
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t;
cin>>t;
while(t--){
int n,m,k,x,y,d,s=1;//s表示步数,由于初始格也算所以初始化为1
cin>>n>>m>>k>>x>>y>>d;
for(int i=1;i<=n;i++){//输入
for(int j=1;j<=m;j++){
cin>>c[i][j];
}
}
while(k--){
c[x][y]=',';//标记搜索过
if(d==0){//判断
if(c[x][y+1]=='.'){
y++,s++;
}else if(c[x][y+1]==','){
y++;
}else{
d=1;
}
}else if(d==1){
if(c[x+1][y]=='.'){
x++,s++;
}else if(c[x+1][y]==','){
x++;
}else{
d=2;
}
}else if(d==2){
if(c[x][y-1]=='.'){
y--,s++;
}else if(c[x][y-1]==','){
y--;
}else{
d=3;
}
}else if(d==3){
if(c[x-1][y]=='.'){
x--,s++;
}else if(c[x-1][y]==','){
x--;
}else{
d=0;
}
}
}
cout<<s<<"\n";
}
return 0;
}
哪个大佬帮忙degug一下让我死心
by nr0728 @ 2024-11-05 21:26:38
@luogu_cod 多测不清空,在 while(t--){
后面加 memset(c,0,sizeof c);
by Lyx8058 @ 2024-11-05 21:27:27
#include <bits/stdc++.h>
using namespace std;
char c[1005][1005]={'x'};
int main(){
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t;
cin>>t;
while(t--){
int n,m,k,x,y,d,s=1;//s表示步数,由于初始格也算所以初始化为1
cin>>n>>m>>k>>x>>y>>d;
for(int i=1;i<=n;i++){//输入
for(int j=1;j<=m;j++){
cin>>c[i][j];
}
}
while(k--){
c[x][y]=',';
if(d==0){//判断
if(c[x][y+1]=='.'&&y+1<=m){
y++,s++;
}else if(c[x][y+1]==','&&y+1<=m){
y++;
}else{
d=1;
}
}else if(d==1){
if(c[x+1][y]=='.'&&x+1<=n){
x++,s++;
}else if(c[x+1][y]==','&&x+1<=n){
x++;
}else{
d=2;
}
}else if(d==2){
if(c[x][y-1]=='.'&&y-1>=1){
y--,s++;
}else if(c[x][y-1]==','&&y-1>=1){
y--;
}else{
d=3;
}
}else if(d==3){
if(c[x-1][y]=='.'&&x-1>=1){
x--,s++;
}else if(c[x-1][y]==','&&x-1>=1){
x--;
}else{
d=0;
}
}
}
cout<<s<<"\n";
}
return 0;
}
by Lyx8058 @ 2024-11-05 21:27:38
@luogu_cod
by SerenityWay @ 2024-11-05 21:28:05
@Lyx8058 哦谢谢大佬
by SerenityWay @ 2024-11-05 21:28:31
@nr0728 懂了谢谢
by sapo1o @ 2024-11-06 09:50:26
@luogu_cod 每侧大样例吧
by SerenityWay @ 2024-11-06 18:19:05
@sapo1o 测了的你可以试一试