hjhjhjkhjkklj @ 2024-10-28 19:02:24
#include<bits/stdc++.h>
#define ll long long
const ll maxn=10050;
using namespace std;
ll t;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
cin>>t;
for(int i=1;i<=t;i++)
{
ll n,m,k,x,y,d,ans=0;
char a[maxn][maxn];
bool f[maxn][maxn];
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];
f[i][j]=0;
}
}
f[x][y]=1;
for(int i=1;i<=k;i++)
{
if(d==0)
{
if(a[x][y+1]=='.')
{
y+=1;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==1)
{
if(a[x+1][y]=='.')
{
x+=1;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==2)
{
if(a[x][y-1]=='.')
{
y-=1;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==3)
{
if(a[x-1][y]=='.')
{
x-=1;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(f[i][j]==1)
{
ans++;
}
}
}
cout<<ans<<endl;
}
return 0;
}
by dendky @ 2024-10-28 19:46:12
sto %%% orz
太强辣!!!
by hjhjhjkhjkklj @ 2024-10-28 19:49:24
比赛的时候样例全对了,现在忘了怎么写了 qwq
by shihaoran666 @ 2024-10-28 20:15:03
#include<bits/stdc++.h>
using namespace std;
const int N = 10050;
int t;
char a[N][N];
bool f[N][N];
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
int n, m, k, x, y, d, 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];
f[i][j] = 0;
}
}
f[x][y] = 1;
for (int i = 1; i <= k; i++) {
if (d == 0) {
if (x > 0 && x <= n && y + 1 > 0 && y + 1 <= m && a[x][y + 1] == '.') {
y += 1;
f[x][y] = 1;
} else {
d = (d + 1) % 4;
}
} else if (d == 1) {
if (x + 1 <= n && x + 1 > 0 && y <= m && y > 0 && a[x + 1][y] == '.') {
x += 1;
f[x][y] = 1;
} else {
d = (d + 1) % 4;
}
} else if (d == 2) {
if (x <= n && x > 0 && y - 1 <= m && y - 1 > 0 && a[x][y - 1] == '.') {
y -= 1;
f[x][y] = 1;
} else {
d = (d + 1) % 4;
}
} else if (d == 3) {
if (x - 1 <= n && x - 1 > 0 && y <= m && y > 0 && a[x - 1][y] == '.') {
x -= 1;
f[x][y] = 1;
} else {
d = (d + 1) % 4;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (f[i][j] == 1) {
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}