社区讨论
为什莫
灌水区参与者 6已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @m0l2nz62
- 此快照首次捕获于
- 2024/09/02 22:04 2 年前
- 此快照最后确认于
- 2025/11/04 21:49 4 个月前
1363
测试点1
input
CPP6 9
#.#.#.#.#
S.#.#.#.#
###.#.###
#...#...#
#.#####.#
#.#...#.#
1 1
S
5 5
#.#.#
..#..
#####
.S#..
#.#.#
output
CPPNo
Yes
No
明明对了为什莫零分
CPP#include <bits/stdc++.h>
#define int long long
#define i128 __int128
#define In(x) freopen(x ".in", "r", stdin)
#define Out(x) freopen(x ".out", "w", stdout)
#define File(x) (In(x), Out(x))
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef std::pair<int, int> PII;
#define pii PII,vector<PII>,greater<PII>
#define mem(f, x) memset(f, x, sizeof(f))
#define kl k << 1
#define kr k << 1 | 1
#define gc() getchar()
#define pc(x) putchar(x)
#define spc putchar(' ')
#define ent putchar('\n')
#define endl '\n'
#define print(x) cerr << #x << '=' << x << endl
#define line cerr << "\n---------------------------------------------------------\n"
#define cout cerr
const int INF = 4557430888798830399;
const double eps = 1e-8;
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
inline int lcm(int x, int y) { return x / gcd(x, y) * y; }
inline int Min(int a, int b, int c) { return std::min(a, std::min(b, c)); }
inline int Max(int a, int b, int c) { return std::max(a, std::max(b, c)); }
inline int lowbit(int x) { return x & -x ; }
namespace fast_IO{
//=================================//
template < typename T >
inline void read(T &x){
bool f = 1;
x = 0;
char ch = getchar();
while ( ch < '0' || ch > '9' ) {
if(ch == '-') f =! f;
ch = getchar();
}
while ( ch >= '0' && ch <= '9' ) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = (f ? x : -x);
}
template < typename T, typename... Args >
inline void read(T& x, Args&...x_) {
read(x);
read(x_...);
}
template < typename T >
inline void write(T x) {
if (x < 0) pc('-'), x = -x;
if (x > 9) write(x / 10);
pc(x % 10 + '0');
}
//=================================//
inline char readc(){
char c = getchar();
while(c == ' ' || c == '\n') c = getchar();
return c;
}
//=================================//
inline void readC(char s[]){
int tot = 0;
char ch = getchar();
while(ch == ' ' || ch == '\n') ch = getchar();
while(ch != ' ' && ch != '\n') s[++tot] = ch,ch = getchar();
}
inline void writeC(char s[],int l){ for(int i = 1;i <= l;i++) putchar(s[i]); }
//=================================//
inline std::string readS(){
char ch = getchar();
std::string s;
while(ch == ' ' || ch == '\n') ch = getchar();
while(ch != ' ' && ch != '\n') s += ch , ch = getchar();
return s;
}
inline void writeS(std::string s) { for (char i : s) putchar(i); }
//=================================//
}
using namespace std;
using namespace fast_IO;
/***************************************************************************************************************************/
/** **/
/***************************************************************************************************************************/
const int MAXN = 3005;
int n,m;
char s[MAXN][MAXN];
const int fx[] = {0,0,-1,1};
const int fy[] = {1,-1,0,0};
bool f[MAXN][MAXN];
void dfs(int x,int y){
f[x][y] = 1;
for(int i = 0;i < 4;i++){
int tx = x + fx[i];
int ty = y + fy[i];
if(tx < 1 || ty < 1 || tx > n || ty > m || s[tx][ty] == '#' || f[tx][ty] == 1) continue;
dfs(tx,ty);
}
}
signed main(){
while(cin >> n >> m){
int sx,sy;
for(int i = 1;i <= n;i++){
readC(s[i]);
for(int j = 1;j <= m;j++) if(s[i][j] == 'S') { sx = i,sy = j; break; }
}
mem(f , 0);
dfs(sx,sy);
bool ans = 0;
for(int i = 1;i <= m;i++){
if(f[1][i] && f[n][i]) {
ans = 1;break;
}
}
for(int i = 1;i <= n;i++){
if(f[i][1] && f[i][m]) {
ans = 1;break;
}
}
if(ans) puts("Yes");
else puts("No");
}
return 0;
}
回复
共 6 条回复,欢迎继续交流。
正在加载回复...