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

AtCoder ABC 025 A&B&C AtCoder - 025

A problem

--Since the input character strings are arranged in ascending order, try assembling the characters as they are -If [a, b, c, d, e] is the input value -[a, a] [a, b] [a, c] ・ ・ ・ [b, a] [b, b] [b, c] ・ ・ ・ [e, a] [e, b] ・ ・ ・ [e, e] ――Since it is in ascending order, it will be in lexicographic order even if you turn the loop as it is.

	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

--Decisive decision as follows --When you are in the east, + coordinates --When in the west-Coordinates --In a fixed state, simply enter $ \ pm $ to see if you are in the east or west at the end.

Hmmm. Stream seems to have no merit even if it is used in such a place.

	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 the explanation, it started from turn = 9, but there was a part that I could not catch up with, so I decided to compare all the points when I put stones in order from turn = 1 ( As a result, it is called a recursive function 623530 times) ――I want to put both in the best place, so I will adopt the maximum score in that turn

--It seems that you can make a memo quickly, but I could not make a memo well, so I will try to deal with it next time

	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();
			}
		}

		/*
		 *Either stone has already been placed, no one has placed it yet
		 *In order to express[][]use
		 *If it is 0, no one is placed
		 * boolean[][]But you can, but for debugging 1/-I wanted to see 1
		 */
		int[] res = calcPointC(b, c, new int[3][3], 0, true);

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

	//	int cnt = 1;

	/**
	 *Investigate recursively
	 * @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;
			/*
			 *I finished putting everything, so I started calculating
			 */
			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[]>();
		/*
		 *Find out the maximum score in who's turn
		 *The score when the maximum score of who does the best
		 */
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				//				if (i == 0 && j == 0) {
				//					out.println(cnt++);
				//				}
				/*
				 *Already placed
				 */
				if (board[i][j] != 0) {
					continue;
				}

				if (who) {
					board[i][j] = 1;
				} else {
					board[i][j] = -1;
				}
				/*
				 *who's turn
				 *For the time being, record how many points you will get if you put it in this position
				 *In the end, here is a squeeze to find out the maximum score in who's turn
				 */
				resList.add(calcPointC(b, c, board, turn + 1, !who));
				/*
				 *Reset the stone placed in this position to change the position
				 */
				board[i][j] = 0;
			}
		}
		/*
		 *The reason why the maximum score is returned alternately is because it is a premise that each person will do his best.
		 *The result of alternately returning the maximum score is result
		 */
		if (who) {
			//Since it is chokudai's turn, return the array containing the maximum value of chokudai
			return resList.stream().max(Comparator.comparing(x -> x[0])).get();
		} else {
			//Since it is chokuko's turn, return the array containing the maximum value of chokuko
			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 Programming Contest A & B & C & D
atcoder ABC113 C problem
ABC093 C --Same Integers
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
A person writing C ++ tried writing Java
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"