hzy6622 @ 2024-11-08 23:02:23
求大佬帮调TVT
using namespace std; char a[1005][1005] = {','}; int main() { int t; cin >> t; while (t--) { int n, m, k, x, y, d, s = 1; 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]; } } while (k--) { if (d == 0) { if (a[x][y + 1] == '.' && y + 1 <= m) { y++; s++; } else if (a[x][y + 1] == ',' && y + 1 <= m) { y++; } else { d = 1; } } else if (d == 1) { if (a[x + 1][y] == '.' && x + 1 <= n) { x++; s++; } else if (a[x + 1][y] == ',' && x + 1 <= n) { x++; } else { d = 2; } } else if (d == 2) { if (a[x][y - 1] == '.' && y - 1 >= 1) { y--; s++; } else if (a[x][y - 1] == ',' && y - 1 >= 1) { y--; } else { d = 3; } } else if (d == 3) { if (a[x - 1][y] == '.' && x - 1 >= 1) { x--; s++; } else if (a[x - 1][y] == ',' && x - 1 >= 1) { x--; } else { d = 0; }
}
}
cout << s << "\n";
}
return 0;
}
by Are_you_sure_yxy @ 2024-11-08 23:25:24
求关
#include<bits/stdc++.h>
using namespace std;
char M[1005][1005];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int vis[1005][1005];
int main()
{
int T,n,m,cnt,k,x,y,d,ny,nx;
cin>>T;
while(T--){
cin>>n>>m>>k;
cin>>x>>y>>d;
cnt=1;
for(int i=0;i<1005;i++)
for(int j=0;j<1005;j++)
M[i][j]='x',vis[i][j]=0;
cnt=1;
vis[x][y]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>M[i][j];
}
while(k--){
nx=x+dx[d],ny=y+dy[d];
if(M[nx][ny]=='x'){d=(d+1)%4;continue;}
x=nx,y=ny;
if(!vis[x][y]) vis[x][y]=1,cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
by BH9570 @ 2024-11-09 07:52:57
#include<bits/stdc++.h>
using namespace std;
int a[6];
char c[1001][1001];
bool b[1001][1001];
int main () {
short t;
cin >> t;
for (int i = 1; i <= t; i++) {
int n,m,k;
short x,y,d;
cin >> n >> m >> k;
cin >> x >> y >> d;
b[x][y] = 1;
for (int j = 1; j <= n; j++) {
for (int l = 1; l <= m; l++) {
cin >> c[j][l];
}
}
for (int j = 1; j <= k; j++) {
if (d == 0) {
if (y + 1 <= m && c[x][y+1] == '.') {
y++;
b[x][y] = 1;
continue;
}
}
if (d == 1) {
if (x + 1 <= n && c[x+1][y] == '.') {
x++;
b[x][y] = 1;
continue;
}
}
if (d == 2) {
if (y - 1 >= 1 && c[x][y-1] == '.') {
y--;
b[x][y] = 1;
continue;
}
}
if (d == 3) {
if (x - 1 >= 1 && c[x-1][y] == '.') {
x--;
b[x][y] = 1;
continue;
}
}
d++;
d %= 4;
}
for (int j = 1; j <= n; j++) {
for (int l = 1; l <= m; l++) {
if (b[j][l] == 1) {
a[i]++;
b[j][l] = 0;
}
}
}
}
for (int i = 1; i <= t; i++) {
cout << a[i] << endl;
}
return 0;
}
by hzy6622 @ 2024-11-10 22:25:19
@Are_you_sure_yxy 已关,谢谢
by hzy6622 @ 2024-11-10 22:36:57
@BH9570 谢谢大佬求助