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

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

A - T or T

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

		out.println(n * a > b ? b : n * a);
	}

B - Good Distance

-Don't forget the condition of $ (i <j) $

	private void solveB() {
		int n = nextInt();
		int d = nextInt();
		int[][] wk = Stream.generate(() -> IntStream.range(0, d).map(i -> nextInt()).toArray()).limit(n)
				.toArray(int[][]::new);

		int res = 0;
		for (int i = 0; i < n; i++) {
			//i <Note j
			for (int j = i + 1; j < n; j++) {
				long tmp = 0;
				for (int k = 0; k < d; k++) {
					tmp += Math.pow(wk[i][k] - wk[j][k], 2);
				}
				long tmpRes = (long) Math.sqrt(tmp);
				if (Math.pow(tmpRes, 2) == tmp) {
					res++;
				}
			}
		}

		out.println(res);
	}

C - Remainder Minimization 2019

――What can you do if you reduce the maximum (r)? --Since it is mod 2019, the number repeats 0 --2018 --Repeat 0-2018 starting from l -Rather than trying everything from $ l to r $, try the smaller of $ l to min (l + (2019 * 2), r) . - 0,1,2 ・ ・ ・ 2018,0,1,2, ・ ・ ・ If you try up to 2018 $, you can select the combination of 0,0 which is the minimum value. --The ideal minimum of two numbers is a combination of 0,0 --When r-l is larger than 2019 * 2 --This is not the case if r-l is less than 2019 * 2.

	private void solveC() {
		final int CONST_MOD = 2019;
		int l = nextInt();
		int r = nextInt();
		/*
		 *Nothing can be done without reducing the maximum for the time being.
		 * l+Adopted the smaller of 2019 or r as the maximum value (because it is a MOD)
		 * l+One cycle in 2019. However, with this, the minimum value comes out only once.
		 * +(2019*2)If you make two laps, 1 will appear twice.
		 *
		 */
		int wkR = Math.min(l + (CONST_MOD * 2), r);
		int res = 2020;
		for (int i = l; i <= wkR; i++) {
			for (int j = i + 1; j <= wkR; j++) {
				res = Math.min(((i % CONST_MOD) * (j % CONST_MOD)) % CONST_MOD, res);
			}
		}

		out.println(res);
	}

D - Rain Flows into Dams

--Simultaneous equations were established and solved --Calculate the shipping cost of the dam and ask for the rain of one mountain somewhere ――If you decide on one mountain, you can decide on the other --Since the number of mountains is odd, it increases as 1-> 3-> 5-> 7-> 9 ... --Since there are always two peaks, the formula repeats +-as follows: --Mountain A = Dam 1 --Dam 2 + Dam 3 --Dam 4 + Dam 5 --+-+-+ ・ ・ ・

Example: 2

dam 3 8 7 5 5
Mountain a B C D E
2 4 12 2 8
	 
Dam 1=Mountain A/2 +Mountain B/2  ->Dam 1*2 =Mountain A +Mountain B  -> Mountain B =Dam 1*2 -Mountain A
Dam 2=Mountain B/2 +Mountain C/2  ->Dam 2*2 =Mountain B +Mountain C  -> Mountain C =Dam 2*2 -Mountain B
Dam 3=Mountain C/2 +Mountain D/2  ->Dam 3*2 =Mountain C +Mountain D  -> Mountain D =Dam 3*2 -Mountain C
Dam 4=Mountain D/2 +Mountain E/2  ->Dam 4*2 =Mountain D +Mountain E  -> Mountain E =Dam 4*2 -Mountain D
Dam 5=Mountain E/2 +Mountain A/2  ->Dam 5*2 =Mountain E +Mountain A  -> Mountain A =Dam 5*2 -Mountain E

First find the mountain A by transforming the above equation
Mountain A=Dam 1-Dam 2+Dam 3-Dam 4+Dam 5
	 
If mountain A is decided, mountain B and beyond will be decided
Mountain B=Dam 1*2 -Mountain A
Mountain C=Dam 2*2 -Mountain B
Mountain D=Dam 3*2 -Mountain C
Mountain E=Dam 4*2 -Mountain D
	private void solveD() {
		int n = nextInt();
		int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();

		long a = 0;

                //Even-numbered dams+, The odd dam-
		for (int i = 0; i < wk.length; i++) {
			if (i % 2 == 0) {
				a += wk[i];
			} else {
				a -= wk[i];
			}
		}
		long[] mountain = new long[n];
		mountain[0] = a;
		//The last mountain is mountain A, so it is excluded
		for (int i = 0; i < mountain.length - 1; i++) {
			mountain[i + 1] = wk[i] * 2 - mountain[i];
		}
		StringBuilder builder = new StringBuilder();
		for (long l : mountain) {
			builder.append(l + " ");
		}
		out.println(builder.toString().trim());
	}

Recommended Posts

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
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 --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
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