liangyimim @ 2024-11-15 21:47:37
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int n,m,k,d,x,y;
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n>>m>>k>>x>>y>>d;
memset(a,'x',sizeof(a));
a[x][y]='l';
int sum=1;
for(int j=1;j<=n;j++)
{
for(int l=1;l<=m;l++)
{
cin>>a[j][l];
}
}
for(int j=0;j<k;j++)
{
if(d==0)
{
if(a[x][y+1]=='x')
{
d=1;
}
else
{
y++;
if(a[x][y]!='l')
{
sum++;
a[x][y]='l';
}
}
}
else if(d==1)
{
if(a[x+1][y]=='x')
{
d=2;
}
else
{
x++;
if(a[x][y]!='l')
{
sum++;
a[x][y]='l';
}
}
}
else if(d==2)
{
if(a[x][y-1]=='x')
{
d=3;
}
else
{
y--;
if(a[x][y]!='l')
{
sum++;
a[x][y]='l';
}
}
}
else
{
if(a[x-1][y]=='x')
{
d=0;
}
else
{
x--;
if(a[x][y]!='l')
{
sum++;
a[x][y]='l';
}
}
}
}
cout<<sum<<endl;
}
return 0;
}
by TimADE @ 2024-11-15 21:49:27
@liangyimim 求关
#include<bits/stdc++.h>
using namespace std;
#define x0 x1111
#define y0 y1111
#define d0 d1111
int t,n,m,k,x0,y0,d0,x,y,d;
char s[1010][1010],s2[1010][1010];
int f(int x,int y,int d){
if(d==0){
if(y+1<=m&&s[x][y+1]!='x')return 1;
else return -1;
}
if(d==1){
if(x+1<=n&&s[x+1][y]!='x')return 1;
else return -1;
}
if(d==2){
if(y-1>=1&&s[x][y-1]!='x')return 1;
else return -1;
}
if(d==3){
if(x-1>=1&&s[x-1][y]!='x')return 1;
else return -1;
}
}
void mov(int d){
if(d==0){
y++;
}
if(d==1){
x++;
}
if(d==2){
y--;
}
if(d==3){
x--;
}
}
int main(){
cin>>t;
for(int i=1;i<=t;i++){
int cnt=0;
cin>>n>>m>>k;
cin>>x0>>y0>>d0;
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
cin>>s[j][k];
s2[j][k]=0;
}
}
x=x0,y=y0,d=d0;
s2[x0][y0]=1;
for(int j=1;j<=k;j++){
if(f(x,y,d)==1){
mov(d);
s2[x][y]=1;
}else{
d=(d+1)%4;
}
}
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
if(s2[j][k]==1)cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}
by liangyimim @ 2024-11-15 22:04:44
@TimADEok,谢谢,已关