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

AtCoder ABC 025 A&B&C AtCoder - 025

Ein Problem

	private void solveA() {
		char[] wk = next().toCharArray();
		int n = nextInt();

		int cnt = 0;
		for (int i = 0; i < wk.length; i++) {
			for (int j = 0; j < wk.length; j++) {
				cnt++;
				if (n == cnt) {
					out.println((char) wk[i] + "" + (char) wk[j]);
					return;
				}
			}
		}

	}

B Problem

Hmmm. Stream scheint keinen Wert zu haben, selbst wenn er an einem solchen Ort verwendet wird.

	private void solveB() {
		int n = nextInt();
		int a = nextInt();
		int b = nextInt();
		long res = 0;

		res = IntStream.range(0, n).reduce(0, (sum, i) -> {
			String direction = next();
			int meter = nextInt();
			long move = meter < a ? a : meter > b ? b : meter;
			switch (direction) {
			case "East":
				sum -= move;
				break;
			case "West":
				sum += move;
				break;
			default:
				throw new IllegalArgumentException();
			}
			return sum;
		});
		//--------------------------------------------------------
		//		String[] direction = new String[n];
		//		int[] meter = new int[n];
		//
		//		for (int i = 0; i < n; i++) {
		//			direction[i] = next();
		//			meter[i] = nextInt();
		//			long move = meter[i] < a ? a : meter[i] > b ? b : meter[i];
		//			switch (direction[i]) {
		//			case "East":
		//				res -= move;
		//				break;
		//			case "West":
		//				res += move;
		//				break;
		//			default:
		//				throw new IllegalArgumentException();
		//			}
		//		}
		//--------------------------------------------------------

		out.println(res == 0 ? 0 : res > 0 ? "West " + res : "East " + res * -1);
	}

C Problem

――In der Erklärung begann es ab Runde = 9, aber es gab einen Teil, den ich nicht einholen konnte, und so beschloss ich, alle Punkte zu vergleichen, wenn ich Steine ab Runde = 1 in die richtige Reihenfolge brachte ( Infolgedessen wird es 623530-mal als rekursive Funktion bezeichnet. ――Ich möchte beide an die beste Stelle setzen, also werde ich in dieser Runde die maximale Punktzahl übernehmen

	private void solveC() {
		int[][] b = new int[2][3];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 3; j++) {
				b[i][j] = nextInt();
			}
		}
		int[][] c = new int[3][2];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 2; j++) {
				c[i][j] = nextInt();
			}
		}

		/*
		 *Jeder Stein wurde bereits platziert, noch hat niemand ihn platziert
		 *Um auszudrücken[][]verwenden
		 *Wenn es 0 ist, wird niemand gesetzt
		 * boolean[][]Aber Sie können, aber zum Debuggen 1/-Ich wollte 1 sehen
		 */
		int[] res = calcPointC(b, c, new int[3][3], 0, true);

		out.println(res[0]);
		out.println(res[1]);
	}

	//	int cnt = 1;

	/**
	 *Rekursiv untersuchen
	 * @param b
	 * @param c
	 * @param board
	 * @param turn
	 * @param who
	 * @return
	 */
	private int[] calcPointC(int[][] b, int[][] c, int[][] board, int turn, boolean who) {
		if (turn == 9) {
			int chokudai = 0;
			int chokuko = 0;
			/*
			 *Ich habe alles fertig gestellt und angefangen zu rechnen
			 */
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i < 2) {
						if (board[i][j] == board[i + 1][j]) {
							chokudai += b[i][j];
						} else {
							chokuko += b[i][j];
						}
					}
					if (j < 2) {
						if (board[i][j] == board[i][j + 1]) {
							chokudai += c[i][j];
						} else {
							chokuko += c[i][j];
						}
					}
				}
			}
			return new int[] { chokudai, chokuko };

		}

		List<int[]> resList = new ArrayList<int[]>();
		/*
		 *Finden Sie die maximale Punktzahl heraus, wer an der Reihe ist
		 *Die Punktzahl, wenn die maximale Punktzahl, wer das Beste tut
		 */
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				//				if (i == 0 && j == 0) {
				//					out.println(cnt++);
				//				}
				/*
				 *Bereits platziert
				 */
				if (board[i][j] != 0) {
					continue;
				}

				if (who) {
					board[i][j] = 1;
				} else {
					board[i][j] = -1;
				}
				/*
				 *Wer ist dran?
				 *Notieren Sie vorerst, wie viele Punkte Sie erhalten, wenn Sie es in diese Position bringen
				 *Am Ende ist hier ein Druck, um die maximale Punktzahl herauszufinden, wer an der Reihe ist
				 */
				resList.add(calcPointC(b, c, board, turn + 1, !who));
				/*
				 *Setzen Sie den in dieser Position platzierten Stein zurück, um die Position zu ändern
				 */
				board[i][j] = 0;
			}
		}
		/*
		 *Der Grund, warum die maximalen Punkte abwechselnd zurückgegeben werden, liegt darin, dass jede Person ihr Bestes geben wird.
		 *Das Ergebnis der abwechselnden Rückgabe der maximalen Punktzahl ist das Ergebnis
		 */
		if (who) {
			//Da Chokudai an der Reihe ist, geben Sie das Array zurück, das den Maximalwert von Chokudai enthält
			return resList.stream().max(Comparator.comparing(x -> x[0])).get();
		} else {
			//Da Chokuko an der Reihe ist, geben Sie das Array zurück, das den Maximalwert von Chokuko enthält
			return resList.stream().max(Comparator.comparing(x -> x[1])).get();
		}

	}

Recommended Posts

ABC - 023 - A & B & C.
ABC - 036-A & B & C.
ABC - 010 - A & B & C.
ABC - 028 - A & B & C.
ABC - 015 - A & B & C.
ABC - 128 - A & B & C.
ABC - 012-A & B & C.
ABC - 018 - A & B & C.
ABC - 054 - A & B & C.
ABC - 029 - A & B & C.
ABC - 022 - A & B & C.
ABC - 020 - A & B & C.
ABC - 030 - 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 - 133 - A & B & C & D.
ABC - 122 - 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 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"