[JAVA] ABC - 007 - A & B & C.

AtCoder ABC 007 A&B&C AtCoder - 007

Sie mögen vielleicht die Probleme der Vergangenheit, weil sie sehr lehrreich sind. C Problem.

A-Ueki-Berechnung

	private void solveA() {
		int n = nextInt();

		out.println(n - 1);
	}

B-Wörterbuch Reihenfolge

――Wenn Sie nur die Wörterbuchreihenfolge berücksichtigen müssen, sollten Sie immer "a" setzen.

	private void solveB() {
		String wk = next();

		if (wk.equals("a")) {
			out.println(-1);
		} else {
			out.println("a");
		}
	}

C-Breite Prioritätssuche

Referenzseite

Lesen Sie am besten die Referenzseite durch

	private void solveC2() {
		int r = nextInt();
		int c = nextInt();
		int sX = nextInt() - 1;
		int sY = nextInt() - 1;
		int gX = nextInt() - 1;
		int gY = nextInt() - 1;

		char[][] map = new char[r][c];
		for (int i = 0; i < r; i++) {
			map[i] = next().toCharArray();
		}
		Deque<Cordinate> que = new ArrayDeque<Cordinate>();
		Cordinate start = new Cordinate();
		start.x = sX;
		start.y = sY;
		start.step = 0;
		/*
		 *Da es als Warteschlange (LIFO) verwendet wird, addLast()
		 */
		que.addLast(start);
		boolean[][] memo = new boolean[r][c];
		memo[sX][sY] = true;
		int res = bfs(map, que, r, c, gX, gY, memo);

		out.println(res);
	}

	private static class Cordinate {
		private int x;
		private int y;
		private int step;
	}

	private static final int[] vX = { 1, 0, 0, -1 };
	private static final int[] vY = { 0, 1, -1, 0 };

	private int bfs(char[][] map, Deque<Cordinate> que, int r, int c, int gX, int gY, boolean[][] memo) {

		while (!que.isEmpty()) {
			/*
			 *RemoveFirst, da es als Warteschlange (LIFO) verwendet wird()
			 */
			Cordinate curr = que.removeFirst();
			if (curr != null) {
				if (curr.x == gX && curr.y == gY) {
					return curr.step;
				}
				for (int i = 0; i < 4; i++) {
					int wkX = curr.x + vX[i];
					int wkY = curr.y + vY[i];
					int step = curr.step + 1;
					if (wkX >= 0 && wkX < r && wkY >= 0 && wkY < c && map[wkX][wkY] != '#' && !memo[wkX][wkY]) {
						Cordinate newC = new Cordinate();
						newC.x = wkX;
						newC.y = wkY;
						newC.step = step;
						/*
						 *Da es als Warteschlange (LIFO) verwendet wird, addLast()
						 */
						que.addLast(newC);
						memo[wkX][wkY] = true;
					}
				}
			}
		}
		return -1;
	}

Recommended Posts

ABC - 013-A & B & C.
ABC - 023 - A & B & C.
ABC - 036-A & B & C.
ABC - 010 - A & B & C.
ABC - 028 - A & B & C.
ABC - 128 - A & B & C.
ABC - 012-A & B & C.
ABC - 018 - A & B & C.
ABC - 054 - A & B & C.
ABC - 017 - A & B & C.
ABC - 029 - A & B & C.
ABC - 022 - A & B & C.
ABC - 019 - A & B & C.
ABC - 020 - A & B & C.
ABC - 030 - A & B & C.
ABC - 127 - A & B & C.
ABC - 007 - A & B & C.
ABC - 132 - A & B & C.
ABC - 026 - A & B & C.
ABC - 014 - A & B & C.
ABC - 016 - A & B & C.
ABC - 011-A & B & C.
ABC - 031 - A & B & C.
ABC - 021 - A & B & C.
ABC - 025 - A & B & C.
ABC - 024 - A & B & C.
ABC - 027 - A & B & C.
ABC - 080 - A & B & C.
ABC - 129 - A & B & C & D.
ABC - 133 - A & B & C & D.
ABC - 125 - A & B & C & D.
ABC - 130 - A & B & C & D.
ABC - 126 - A & B & C & D.
ABC - 134 - A & B & C & D & E.
ABC - 131 - A & B & C & D & E.
diverta 2019 Programmierwettbewerb A & B & C & D.
AtCoder Anfängerwettbewerb 169 A, B, C mit Rubin
atcoder ABC113 C Problem
ABC093 C - Gleiche Ganzzahlen
atcoder ABC115 C Problem
AtCoder Anfängerwettbewerb 170 A, B, C bis Rubin
Eine Person, die C ++ schreibt, hat versucht, Java zu schreiben
Machen Sie einen SOAP-Aufruf in C #
Rufen Sie C-Sprachfunktionen von Swift aus auf
NLP4J 100 Sprachverarbeitungsklopfen mit NLP4J # 34 "A B"