B. Phillip and Trains

 

 

http://codeforces.com/contest/585/problem/B

 

 

模拟

 

 

 1 
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner io = new Scanner(System.in);
 6         int t = io.nextInt();
 7         int[][]g=new int[400][400];
 8         //不优化的话队列里会有很多重复成员
 9         int[][]vis=new int[400][400];
10         int[]dy=new int[]{0,1,-1};
11 
12         OUT:
13         while (t-->0){
14             int x0 =io.nextInt(),k=io.nextInt();
15             for (int i = 0; i < g.length; i++){ Arrays.fill(g[i],'.');Arrays.fill(vis[i],0);}
16 
17             ArrayDeque<int[]>q=new ArrayDeque();
18             for (int i = 1; i <= 3; i++) {
19                 String s=io.nextLine();while (s.length()==0)s=io.nextLine();
20                 for (int j = 0; j < s.length(); j++){
21                      if ((g[j+1][i]=s.charAt(j))=='s')q.add(new int[]{j+1,i});
22                 }
23             }
24             while (!q.isEmpty()){
25                 int[]s=q.poll();int x=s[0],y=s[1];
26 
27                 //往前走一步
28                 int xx=x+1,yy=y;
29                 if (g[xx][yy]>='A'&&g[xx][yy]<='Z')continue ;
30 
31                 //往上走、不动、往下走
32                 for (int i = 0; i < dy.length; i++) {
33                      yy=y+dy[i];
34                     if (yy<1||yy>3)continue ;
35                     if (g[xx][yy]>='A'&&g[xx][yy]<='Z')continue ;
36                     if (g[xx+1][yy]>='A'&&g[xx+1][yy]<='Z')continue ;
37                     if (g[xx+2][yy]>='A'&&g[xx+2][yy]<='Z')continue ;
38 
39                     if (xx+2>x0){ System.out.println("YES");continue OUT;}
40                     if (vis[xx+2][yy]==0) {
41                         q.add(new int[]{xx+2,yy});vis[xx+2][yy]=1;
42                     }
43 
44                 }
45             }
46             System.out.println("NO");
47         }
48     }
49   
50 }

 

posted @ 2019-07-24 15:32  dodoBehind  阅读(197)  评论(0编辑  收藏  举报