Alg_orithm @ 2024-11-06 16:28:55
#include<bits/stdc++.h>
using namespace std;
char a[1010][1010];
bool b[1010][1010];
int n,m;
inline bool ch(int x,int y)
{
if(x<=0||x>n||y<=0||y>m||a[x][y]=='x') return false;
return true;
}
int main()
{
//freopen("explore5.in","r",stdin);
//freopen("explore.out","w",stdout);
int t,k,x,y,d,nx,ny,i,j;
scanf("%d",&t);
while(t--)
{
memset(b,0,sizeof(b));
scanf("%d%d%d%d%d%d",&n,&m,&k,&x,&y,&d);
b[x][y]=1;
for(i=1;i<=n;i++) scanf("%s",a[i]+1);
while(k--)
{
b[x][y]=1;
nx=x;ny=y;
if(d==0) ny++;
if(d==1) nx++;
if(d==2) ny--;
if(d==3) nx--;
if(ch(nx,ny))
{
b[nx][ny]=1;
x=nx;y=ny;
continue;
}
bool bb=1;
for(i=1;i<4;i++)
{
d=(d+1)%4;
nx=x;ny=y;
if(d==0) ny++;
if(d==1) nx++;
if(d==2) ny--;
if(d==3) nx--;
if(ch(nx,ny))
{
b[x][y]=1;
bb=0;
break;
}
}
if(bb) break;
}
long long ans=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(b[i][j])
ans++;
printf("%lld\n",ans);
}
return 0;
}
by lyc20130626 @ 2024-11-06 16:31:02
#include <bits/stdc++.h>
using namespace std;
char c[1005][1005]={'x'};
int main(){
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
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>>c[i][j];
}
}
while(k--){
c[x][y]=',';
if(d==0){
if(c[x][y+1]=='.'&&y+1<=m){
y++,s++;
}else if(c[x][y+1]==','&&y+1<=m){
y++;
}else{
d=1;
}
}else if(d==1){
if(c[x+1][y]=='.'&&x+1<=n){
x++,s++;
}else if(c[x+1][y]==','&&x+1<=n){
x++;
}else{
d=2;
}
}else if(d==2){
if(c[x][y-1]=='.'&&y-1>=1){
y--,s++;
}else if(c[x][y-1]==','&&y-1>=1){
y--;
}else{
d=3;
}
}else if(d==3){
if(c[x-1][y]=='.'&&x-1>=1){
x--,s++;
}else if(c[x-1][y]==','&&x-1>=1){
x--;
}else{
d=0;
}
}
}
cout<<s<<"\n";
}
return 0;
}
by lyc20130626 @ 2024-11-06 16:32:21
求关
by complete_binary_tree @ 2024-11-06 16:46:53
转一次算一步操作,一步操作不能转很多次。
所以如果前进不成功只能转一次。
(理论上只能得