[JAVA] ABC --130- A & B & C & D

AtCoder ABC 130 A&B&C&D AtCoder - 130

E and F will be updated soon

A - Rounding

	private void solveA() {
		int x = nextInt();
		int a = nextInt();

		out.println(x < a ? 0 : 10);
	}

B - Bounding

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

		int d = 0;
		//Be sure to D1=Since it bounces at 0, it starts from 1
		int cnt = 1;

		for (int i = 0; i < wk.length; i++) {
			d = d + wk[i];
			if (d <= x) {
				cnt++;
			}
		}

		out.println(cnt);
	}

C - Rectangle Cutting

--I misread it --About dividing a rectangle into two parts with a straight line passing through (x, y) --The straight line passing through (x, y) intersects the outer circumference of the rectangle at right angles. (The subject is not always a right angle) --If it does not intersect at right angles to the outer circumference, it is possible to bisect the rectangle by drawing a straight line through the center of gravity of the rectangle (because it is a rectangle). --Therefore, the maximum divided value is half the area of the original rectangle. --When (x, y) is the center of gravity, you can draw multiple straight lines to divide --Rather, if (x, y) is not the center of gravity, only one straight line can be drawn.

	private void solveC() {
		double w = nextInt();
		double h = nextInt();
		double x = nextInt();
		double y = nextInt();

		double res = (w * h) / 2;
		String ref = String.format("%.10f", res);
		int bF = 0;
		if (w == 2 * x && h == 2 * y) {
			bF = 1;
		}
		out.println(ref + " " + bF);
	}

D - Enough Array

--It will be easier if you can read the problem ――Rather than searching for "combinations that exceed K", "subtract combinations that do not exceed K from the total number of combinations" ――By doing this, you will be able to count by the scale method. ――I think there is a way to count "combinations that exceed K", but I couldn't think of it.

	private void solveD() {
		int n = nextInt();
		long k = nextLong();
		//		int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();
		long[] wk = new long[n];
		for (int i = 0; i < n; i++) {
			wk[i] = nextLong();
		}

		long res = 0;
		long total = 0;
		int right = 0;
		/*
		 *It seems difficult to count "combinations that exceed K", so
		 *With the policy of "subtracting combinations that do not exceed K from the total number of combinations"
		 */
		for (int left = 0; left < n; left++) {
			//wk to total[right]If you can add right++
			while (right < n && total + wk[right] < k) {
				total += wk[right];
				right++;
			}
			//right is the maximum that satisfies the condition
			res += (right - left);

			if (right == left) {
				right++;
			} else {
				total -= wk[left];
			}

		}

		/*
		 *Total number of combinations ignoring k
		 *Since it is a subsequence, n* (n+1)
		 *If you forget to cast to long, it becomes int and WA
		 */
		long totalCnt = (long) n * ((long) n + 1L) / 2L;
		out.println(totalCnt - res);
	}

Recommended Posts

ABC --129- A & B & C & D
ABC --122 --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
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 --015 --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 --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
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
atcoder ABC70 D 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
What is a Ruby 2D array?
Convert Swift 2D array to C 2D array