zhangziyao1126 @ 2024-11-16 23:08:49
#include<bits/stdc++.h>
using namespace std;
int t,n,m,d,k,x,y,ans;
char a[1010][1010];
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];
}
}
for(int i=1;i<=k;i++){
if(d==0){
if(a[x][y+1]=='.'&&y+1<=m){
y++;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==1){
if(a[x+1][y]=='.'&&x+1<=n){
x++;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==2){
if(a[x][y-1]=='.'&&y-1>=1){
y--;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==3){
if(a[x-1][y]=='.'&&x-1>=1){
x--;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==1){
ans++;
}
}
}
cout<<ans<<endl;
ans=0;
}
return 0;
}
by cyw2011 @ 2024-12-03 20:13:46
#include<bits/stdc++.h>
using namespace std;
int t,n,m,d,k,x,y,ans;
char a[1010][1010];
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];
}
}
a[x][y]=1;
for(int i=1;i<=k;i++){
if(d==0){
if(a[x][y+1]!='x'&&y+1<=m){
y++;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==1){
if(a[x+1][y]!='x'&&x+1<=n){
x++;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==2){
if(a[x][y-1]!='x'&&y-1>=1){
y--;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}else if(d==3){
if(a[x-1][y]!='x'&&x-1>=1){
x--;
}else{
d=(d+1)%4;
}
a[x][y]=1;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==1){
ans++;
}
}
}
cout<<ans<<endl;
ans=0;
}
return 0;
}
by cyw2011 @ 2024-12-03 20:15:07
条件判断少判断了走过的路,还没有把初始化起点@zhangziyao1126
by zhangziyao1126 @ 2024-12-08 11:17:12
@cyw2011 谢谢大佬,已关!