Redl1ght_S @ 2024-10-28 16:00:31
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define rgi register int
using namespace std;
int T, n, m, k, x, y, d0;
char deck[1005][1005];
inline void simulation(int steps){
bool book[1005][1005] = {false};
int cnt = 0;
int xn = x, yn = y, dn = d0;
for(int i=1; i<=steps; ++i){
book[xn][yn] = true;
int xt, yt;
if(dn == 0){
xt = xn; yt = yn+1;
}else if(dn == 1){
xt = xn+1; yt = yn;
}else if(dn == 2){
xt = xn; yt = yn-1;
}else if(dn == 3){
xt = xn-1; yt = yn;
}
if((1 <= xt && xt <= n) && (1 <= yt && yt <= m) && (deck[xt][yt] == '.')){
xn = xt; yn = yt;
}else{
dn = (dn + 1) % 4;
}
}
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
if(book[i][j])
cnt++;
}
}
cout << cnt << '\n';
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
while(T--){
cin >> n >> m >> k >> x >> y >> d0;
memset(deck, 0x7f, sizeof(deck));
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
cin >> deck[i][j];
simulation(k);
}
return 0;
}
by huanglihuan @ 2024-10-28 16:26:11
@Redl1ght_S
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define rgi register int
using namespace std;
int T, n, m, k, x, y, d0;
char deck[1005][1005];
inline void simulation(int steps){
bool book[1005][1005] = {false};
int cnt = 0;
int xn = x, yn = y, dn = d0;
for(int i=1; i<=steps; ++i){
book[xn][yn] = true;
int xt, yt;
if(dn == 0){
xt = xn; yt = yn+1;
}else if(dn == 1){
xt = xn+1; yt = yn;
}else if(dn == 2){
xt = xn; yt = yn-1;
}else if(dn == 3){
xt = xn-1; yt = yn;
}
if((1 <= xt && xt <= n) && (1 <= yt && yt <= m) && (deck[xt][yt] == '.')){
xn = xt; yn = yt;
}else{
dn = (dn + 1) % 4;
}
}
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
if(book[i][j])
cnt++;
}
}
cout << cnt << '\n';
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
while(T--){
cin >> n >> m >> k >> x >> y >> d0;
memset(deck, 0x7f, sizeof(deck));
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
cin >> deck[i][j];
simulation(k+1);
}
return 0;
}
by huanglihuan @ 2024-10-28 16:27:31
@Redl1ght_S 因为初始不算一次,所以
by Redl1ght_S @ 2024-10-28 16:28:04
@huanglihuan 好的谢谢