_ScreamBrother_ @ 2024-11-05 13:47:11
#include <bits/stdc++.h>
#define int long long
const int dir[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
char mp[1010][1010] = {};
bool vis[1010][1010] = {};
// 多测清空!!!!!!!!!!!!!!!!
signed main() {
// freopen("explore.in", "r", stdin), freopen("explore.out", "w", stdout);
int T;
scanf("%d", &T);
while (T --) {
memset(vis, false, sizeof vis), memset(mp, 0, sizeof mp);
int N, M, K, sx, sy, d, ans = 0, x, y;
scanf("%d%d%d%d%d%d", &N, &M, &K, &sx, &sy, &d);
vis[sx][sy] = true, x = sx, y = sy;
for (int i = 1; i <= N; i ++) scanf("%s", mp[i] + 1);
while (K --) {
int nx = x + dir[d][0], ny = y + dir[d][1];
if (nx >= 1 && ny >= 1 && nx <= N && ny <= M && mp[nx][ny] == '.')
vis[nx][ny] = true, x = nx, y = ny;
else d = (d + 1) % 4;
}
for (int i = 1; i <= N; i ++)
for (int j = 1; j <= M; j ++) ans += vis[i][j];
printf("%d\n", ans);
}
return 0;
}
by _th_tw_on_ @ 2024-11-05 13:51:43
请使用 %lld
by _th_tw_on_ @ 2024-11-05 13:51:52
@ScreamBrother
by _ScreamBrother_ @ 2024-11-05 13:52:45
@_th_twon 你说的对,但是我想知道为什么这样会TLE
by _th_tw_on_ @ 2024-11-05 13:56:21
@ScreamBrother 哥们你这不是 RE 吗?
by _ScreamBrother_ @ 2024-11-05 13:57:51
@_th_twon 记录
by _th_tw_on_ @ 2024-11-05 14:00:42
@ScreamBrother ???
by airyns @ 2024-11-05 17:11:41
好歹没tle了
等我再调一下
#include <bits/stdc++.h>
#define int long long
const int dir[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
char mp[1010][1010];
bool vis[1010][1010];
signed main() {
// freopen("explore.in", "r", stdin), freopen("explore.out", "w", stdout);
int T;
scanf("%d", &T);
if (T == 0) return 0;
do {
T--;
int cnt = 1;
memset(vis, false, sizeof(vis));
memset(mp, 0, sizeof(mp));
int N, M, K, sx, sy, d, ans = 0, x, y;
scanf("%d%d%d%d%d%d", &N, &M, &K, &sx, &sy, &d);
vis[sx][sy] = true, x = sx, y = sy;
for (int i = 1; i <= N; i ++) scanf("%s", mp[i] + 1);
do {
K--;
int nx = x + dir[d][0], ny = y + dir[d][1];
if (nx >= 1 && ny >= 1 && nx <= N && ny <= M && mp[nx][ny] == '.')
{
if (vis[nx][ny]) break;
vis[nx][ny] = true;
x = nx, y = ny;
cnt ++;
// if (!vis[nx][ny]) cnt ++;
// vis[nx][ny] = true;
// x = nx, y = ny;
}
else d = (d + 1) % 4;
}while(K);
printf("%d\n", cnt);
}while (T);
return 0;
}
by airyns @ 2024-11-05 17:13:06
我是啥子
非要加条没必要的优化
AC了
#include <bits/stdc++.h>
#define int long long
const int dir[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
char mp[1010][1010];
bool vis[1010][1010];
signed main() {
// freopen("explore.in", "r", stdin), freopen("explore.out", "w", stdout);
int T;
scanf("%d", &T);
if (T == 0) return 0;
do {
T--;
int cnt = 1;
memset(vis, false, sizeof(vis));
memset(mp, 0, sizeof(mp));
int N, M, K, sx, sy, d, ans = 0, x, y;
scanf("%d%d%d%d%d%d", &N, &M, &K, &sx, &sy, &d);
vis[sx][sy] = true, x = sx, y = sy;
for (int i = 1; i <= N; i ++) scanf("%s", mp[i] + 1);
do {
K--;
int nx = x + dir[d][0], ny = y + dir[d][1];
if (nx >= 1 && ny >= 1 && nx <= N && ny <= M && mp[nx][ny] == '.')
{
// if (vis[nx][ny]) break;
// vis[nx][ny] = true;
// x = nx, y = ny;
// cnt ++;
if (!vis[nx][ny]) cnt ++;
vis[nx][ny] = true;
x = nx, y = ny;
}
else d = (d + 1) % 4;
}while(K);
printf("%d\n", cnt);
}while (T);
return 0;
}
by _ScreamBrother_ @ 2024-11-05 17:57:35
@airyns 我的意思是我把 scanf
里的 %d
改成 %lld
就过了
by _ScreamBrother_ @ 2024-11-05 18:00:16
@airyns 怎么用 do-while
就过了?????验证码 RR9R
祭