P_ZXY_ @ 2024-11-21 21:18:36
rt.
#include<iostream>
using namespace std;
struct node{
char t;
int checkk;
}a[1145][1145];
int T,n,m,k,x,y,d,ans = 1;
int xw[11] = {0,1,0,-1},yw[11] = {1,0,-1,0};
int main(){
cin >> T;
while(T--){
cin >> n >> m >> k >> x >> y >> d;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> a[i][j].t;
a[i][j].checkk = 0;
}
}
ans = 1;a[x][y].checkk = 1;
if(a[x-1][y].t == 'x' && a[x][y-1].t == 'x' && a[x][y+1].t == 'x' && a[x+1][y].t == 'x') cout << 1 << endl;
else{
while(k--){
if(a[x+xw[d]][y+yw[d]].t == '.'){
x = x+xw[d],y = y+yw[d];
if(a[x][y].t == '.' && a[x][y].checkk == 0){
++ans;
a[x][y].checkk = 1;
}
}else d = (d+1) % 4;
}
}
cout << ans << endl;
}
return 0;
}
by P_ZXY_ @ 2024-11-21 21:24:31
提交记录
已用官方数据测评,基本5组数据AC 3~4组
by pika_ @ 2024-11-21 22:20:58
调好啦!~
#include<iostream>
using namespace std;
struct node{
char t;
int checkk;
}a[1145][1145];
int T,n,m,k,x,y,d,ans = 1;
int xw[11] = {0,1,0,-1},yw[11] = {1,0,-1,0};
int main(){
cin >> T;
while(T--){
cin >> n >> m >> k >> x >> y >> d;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> a[i][j].t;
a[i][j].checkk = 0;
}
}
ans = 1;a[x][y].checkk = 1;
if(a[x-1][y].t == 'x' && a[x][y-1].t == 'x' && a[x][y+1].t == 'x' && a[x+1][y].t == 'x') cout << 1 << endl;
else{
while(k--){
if(a[x+xw[d]][y+yw[d]].t == '.' && x+xw[d]>=1 && x+xw[d]<=n && y+yw[d]>=1 && y+yw[d]<=m){ // 这里! 加边界判断!
x = x+xw[d],y = y+yw[d];
if(a[x][y].t == '.' && a[x][y].checkk == 0){
++ans;
a[x][y].checkk = 1;
}
}else d = (d+1) % 4;
}
}
cout << ans << endl;
}
return 0;
}
不加边界判断就可能会走出去哦~
by P_ZXY_ @ 2024-11-28 21:45:39
大佬 orz,跪谢已关