跳到正文

个人记录

1

Pizar约 1 分钟
原文

这是 2026年10月1日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月1日
收录
2026年10月1日
更新
2026年11月10日
篇幅
约 1 分钟

版本

  1. v7当前
  2. v6
  3. v5
  4. v4
更早的 3 个版本
  1. v3
  2. v2
  3. v1
C++
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int n,m,k;
char s[N][N];
bool vis[N][N];
void solve(){
	cin>>n>>m>>k;
	int x0,y0,d0;
	cin>>x0>>y0>>d0;
	vis[x0][y0]=1;
	
	for(int i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	while(k--){
		int tx=x0,ty=y0,td=d0;
		if(d0==0)ty++;
		if(d0==1)tx++;
		if(d0==2)ty--;
		if(d0==3)tx--;
		if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&s[tx][ty]=='.')
			vis[tx][ty]=1,x0=tx,y0=ty,d0=td;
		else d0=(d0+1)%4;
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			ans+=vis[i][j];
	printf("%d\n",ans);

	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			vis[i][j]=0;
}
int main(){
	int T;cin>>T;
	while(T--)solve();
}