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

AtCoder ABC 031 A&B&C AtCoder - 031

A problem


	private void solveA() {
		int a = nextInt();
		int d = nextInt();
		int res = 0;
		if (a > d) {
			res = a * (d + 1);
		} else {
			res = d * (a + 1);
		}

		out.println(res);
	}

B problem

	private void solveB() {
		int numL = nextInt();
		int numH = nextInt();
		int numN = nextInt();
		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();

		for (int i : wk) {

			if (i < numL) {
				out.println(numL - i);
			} else if (numH < i) {
				out.println(-1);
			} else {
				out.println(0);
			}
		}

	}

C problem

--Brute force ――It took more than an hour to make the question sentence meaningful due to reading comprehension, but ... ――I implemented it according to the following policy, so is it okay?

  1. First, determine the position of Takahashi between 0 and N
  2. With the position of Takahashi decided, decide where Aoki can get the highest point. 2-1. Aoki decides the location between 0-> N
  3. While moving Aoki's selection position from 0-> N, save Takahashi's point when Aoki's point is maximized.
  4. The answer is the maximum Takahashi point when looping [1-3] and moving Takahashi's position from 0-> N.

I'm not confident that I can get the same answer again. .. ..

	private void solveC() {
		int numN = nextInt();
		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();

		int res = Integer.MIN_VALUE;

		/*
		 *Brute force where Takahashi chooses
		 *Aoki's hand is decided depending on the place Takahashi chose
		 *Should be. .. ..
		 * i=Takahashi's selection place
		 */
		for (int i = 0; i < numN; i++) {
			/*
			 * Integer.MIN_When I set it to VALUE, the value was looped to the MAX side, so ...
			 *Points of Takahashi and Aoki when Takahashi selects this position
			 */
			int aokiPoint = -1000000;
			int takahashiPoint = 0;

			/*
			 *With the selected position of Takahashi fixed
			 *Find Aoki's selection location
			 *This selection place is where Aoki's point is the maximum
			 * i==When it is j, Takahashi and his hand are covered, so he cannot select it.
			 *The point of Takahashi is where Aoki's point is the largest.
			 *
			 */
			for (int j = 0; j < numN; j++) {
				if (i == j) {
					continue;
				}
				int innerAoki = -100000;
				int innerTakahashi = 0;
				/*
				 *The smaller one starts at the selected position of either Aoki or Takahashi
				 *The larger selection position of either Aoki or Takahashi ends
				 *Since both ends are included, the end is<=
				 */
				int cnt = 1;
				for (int k = Integer.min(i, j); k <= Integer.max(i, j); k++) {
					/*
					 *Odd is Takahashi's point
					 *Even numbers are Aoki's points
					 */
					if ((cnt & 1) == 1) {
						innerTakahashi += wk[k];
					} else {
						innerAoki += wk[k];
					}
					cnt++;
				}
				/*
				 *Aoki's point when this position is selected is
				 *Whether it is larger than Aoki's points so far
				 *If it is large, Takahashi's point is confirmed with this
				 */
				if (innerAoki > aokiPoint) {
					//If it is larger than Aoki's point so far, replace it
					aokiPoint = innerAoki;
					//Aoki's points are bigger than before, so Takahashi's points are also replaced
					takahashiPoint = innerTakahashi;
				}
			}
			/*
			 *Whether or not this Takahashi's choice is greater than the previous points
			 */
			res = Integer.max(res, takahashiPoint);

		}

		out.println(res);
	}

Recommended Posts

ABC --013-A & B & C
ABC --023 --A & B & C
ABC --036-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 --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 --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
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
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"