qj10 @ 2024-11-19 18:04:24
#include<iostream>
using namespace std;
int t,n,m,k,x,y,d;
char s[1005][1005];
bool vis[1005][1005];
int ex(){
int cnt = 1;
vis[x][y] = 1;
for(int i=1;i<=k;i++){
if(d==0){
if(s[x][y+1]=='x'|| x<1 || y+1<1 || x>n || y+1>m){
d = (d%4)+1;
continue;
}else{
y++;
if(vis[x][y]==0) cnt++,vis[x][y]=1;
else y--;
}
}else if(d==1){
if(s[x+1][y]=='x'|| x+1<1 || y<1 || x+1>n || y>m){
d = (d%4)+1;
continue;
}else{
x++;
if(vis[x][y]==0) cnt++,vis[x][y]=1;
else x--;
}
}else if(d==2){
if(s[x][y-1]=='x'|| x<1 || y-1<1 || x>n || y-1>m){
d = (d%4)+1;
continue;
}else{
y--;
if(vis[x][y]==0) cnt++,vis[x][y]=1;
else y++;
}
}else{
if(s[x-1][y]=='x'|| x-1<1 || y<1 || x-1>n || y>m){
d = 0;
continue;
}else{
x--;
if(vis[x][y]==0) cnt++,vis[x][y]=1;
else x++;
}
}
}
return cnt;
}
int main(){
cin>>t;
while(t--){
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>s[i][j];
vis[i][j] = 0;
}
}
cout<<ex()<<endl;
}
return 0;
}
by dg114514 @ 2024-11-19 18:15:28
your code are very conplex,see my code(in the contest)
#include<bits/stdc++.h>
#define _int long long
using namespace std;
constexpr int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int vis[1505][1505];
char mp[1505][1505];
void solve(){
int n,m,k,x,y,d,nx,ny,cnt=0;
cin>>n>>m>>k>>x>>y>>d;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>mp[i][j];k++;
while(k--){
vis[x][y]=1;
nx=x+dx[d],ny=y+dy[d];
if(nx<1||nx>n||ny<1||ny>m||mp[nx][ny]=='x'){
d=d+1&3;
continue;
}
x=nx,y=ny;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(vis[i][j])
cnt++;
vis[i][j]=0;
}
cout<<cnt<<"\n";
}
int main(){
// freopen("explore.in","r",stdin);
// freopen("explore.out","w",stdout);
int T;
cin>>T;
while(T--) solve();
}
by dg114514 @ 2024-11-19 18:15:47
@qj10
by Mr_Terminator @ 2024-11-19 18:26:38
@dg114514 huh, pronunciation mistake. recall your direct-solution shitname bro.
by Mr_Terminator @ 2024-11-19 18:28:05
@dg114514 已举报
by dg114514 @ 2024-11-19 19:05:24
@Mr_Terminator?这就举报?6