Exemplo n.º 1
0
    protected String solve(Scanner sc) {
      int N = sc.nextInt();
      int K = sc.nextInt();
      char[][] board = new char[N][];
      for (int i = 0; i < N; i++) board[i] = sc.next().toCharArray();
      char[][] rot = new char[N][N];
      for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) rot[i][j] = board[N - j - 1][i];
      char[][] grav = new char[N][N];
      for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) grav[i][j] = '.';
      for (int i = 0; i < N; i++)
        for (int j = N - 1, c = 0; j >= 0; j--)
          if (rot[j][i] == '.') c++;
          else grav[j + c][i] = rot[j][i];
      //			for (char[] cs : grav)
      //				debug(new String(cs));
      int[][][] R = new int[N][N][4];
      int[][][] B = new int[N][N][4];
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          switch (grav[i][j]) {
            case 'B':
              {
                for (int d = 0; d < 4; d++)
                  B[i][j][d] = (in(i + di[d], j + dj[d], N) ? B[i + di[d]][j + dj[d]][d] : 0) + 1;
                break;
              }
            case 'R':
              {
                for (int d = 0; d < 4; d++)
                  R[i][j][d] = (in(i + di[d], j + dj[d], N) ? R[i + di[d]][j + dj[d]][d] : 0) + 1;
                break;
              }
          }
      boolean Rwin = false, Bwin = false;
      for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
          for (int d = 0; d < 4; d++) {
            if (R[i][j][d] >= K) Rwin = true;
            if (B[i][j][d] >= K) Bwin = true;
          }

      return Rwin ? Bwin ? "Both" : "Red" : Bwin ? "Blue" : "Neither";
    }
Exemplo n.º 2
0
Arquivo: C.java Projeto: jmankhan/ACM
  public void solve() throws Exception {
    n = in.nextInt();
    m = in.nextInt();

    graph = new char[n][m];
    cracked = new boolean[n][m];

    for (int i = 0; i < n; i++) {
      graph[i] = in.next().trim().toCharArray();
    }
    sx = in.nextInt() - 1;
    sy = in.nextInt() - 1;

    gx = in.nextInt() - 1;
    gy = in.nextInt() - 1;

    cracked[sx][sy] = true;

    if (sx == gx && sy == gy) {
      if (graph[sx][sy] == 'X') {}
    }

    int scount = 0;
    for (int i = 0; i < 4; i++) {
      int nx = sx + dx[i];
      int ny = sy + dy[i];
      if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) {
        continue;
      }

      if (graph[nx][ny] == '.') {
        scount++;
      }
    }

    int gcount = 0;
    for (int i = 0; i < 4; i++) {
      int nx = gx + dx[i];
      int ny = gy + dy[i];
      if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) {
        continue;
      }

      if (graph[nx][ny] == '.') {
        gcount++;
      }
    }

    boolean isNeighbors = false;

    for (int i = 0; i < 4 && !isNeighbors; i++) {
      int nx = sx + dx[i];
      int ny = sy + dy[i];
      if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) {
        continue;
      }
      if (nx == gx && ny == gy) {
        isNeighbors = true;
      }
    }

    if (sx == gx && sy == gy) {
      if (graph[sx][sy] == 'X') {
        if (scount >= 1) {
          out.println("YES");
        } else {
          out.println("NO");
        }
      } else {
        if (scount >= 2) {
          out.println("YES");
        } else {
          out.println("NO");
        }
      }
    } else if (isNeighbors) {
      if (graph[gx][gy] == 'X') {
        out.println("YES");
      } else {
        if (gcount >= 1) {
          out.println("YES");
        } else {
          out.println("NO");
        }
      }
    } else if (dfs(sx, sy)) {
      if (graph[gx][gy] == 'X') {
        out.println("YES");
      } else {
        if (gcount >= 2) {
          out.println("YES");
        } else {
          out.println("NO");
        }
      }
    } else {
      out.println("NO");
    }
  }