wuzhexu @ 2024-11-08 20:29:33
重申:因为本人太弱,所以代码也很烂
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int T,N,M,K;
int ans=1;
int x,y,d;
char xy[1005][1005];
for(int i=0;i<1005;i++) for(int j=0;j<1005;j++) xy[i][j]='x';
cin>>T;
for(int i=1;i<=T;i++){
cin>>N>>M>>K;
cin>>x>>y>>d;
for(int o=1;o<=N;o++) for(int j=1;j<=M;j++) cin>>xy[o][j];
for(int j=0;j<K;j++){
if(xy[x][y+1]=='.' && d==0){
y+=1;
ans+=1;
}
else if(d==1 && xy[x+1][y]=='.'){
x+=1;
ans++;
}
else if(d==2 && xy[x][y-1]=='.'){
y-=1;
ans+=1;
}
else if(d==3 && xy[x-1][y]=='.'){
y-=1;
ans+=1;
}
else{
d=(d+1)%4;
}
}
cout<<ans<<endl;
ans=1;
}
}
by yangyuhan_yyh @ 2024-11-08 20:34:01
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d,b[1001][1001];
char a[1001][1001];
int main(){
int t;cin>>t;
for(int q=1;q<=t;q++){
long long sum=0,ans=0;
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];b[i][j]=0;
if(a[i][j]=='.')ans++;
}
}b[x][y]=1;
while(k>0&&ans>0){
while((k>0)&&((d==0&&a[x][y+1]=='x')||(d==1&&a[x+1][y]=='x')||(d==2&&a[x][y-1]=='x')||(d==3&&a[x-1][y]=='x')||(d==0&&y+1>m)||(d==1&&x+1>n)||(d==2&&y-1<=0)||(d==3&&x-1<=0))){
d=(d+1)%4,k--;
}if(d==0)y++;
else if(d==1)x++;
else if(d==2)y--;
else if(d==3)x--;
k--;if(k>=0){
b[x][y]++;
if(b[x][y]==1)ans--;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]!=0)sum++;
}
}cout<<sum<<endl;
}
return 0;
}
by DUhongchang120303 @ 2024-11-09 09:22:28
太厉害了