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

AtCoder ABC 024 A&B&C AtCoder - 024

2019/05/27 Problem name correction Fixed C problem code writing ʻint [] [] generation part `

A-Zoo

――For the time being, if you are eligible for a discount after adding up, you can discount

	private void solveA() {
		int[] first = IntStream.range(0, 4).map(i -> nextInt()).toArray();
		int[] second = IntStream.range(0, 2).map(i -> nextInt()).toArray();

		int child = second[0] * first[0];
		int adult = second[1] * first[1];
		int total = child + adult;
		int sum = Arrays.stream(second).sum();
		if (sum >= first[3]) {
			total -= (sum * first[2]);
		}
		out.println(total);

	}

B-Automatic door

--I will post the process as it is --Comment out the simplification

――I can't get an explanation of the solution. .. ..

	private void solveB() {
		int numN = nextInt();
		int numT = nextInt();
		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();
		long res = 0;
		long preTime = 0;
		for (int i = 0; i < wk.length; i++) {
			long openTime = 0;
			long currentTime = wk[i];
			if (i == 0) {
				preTime = currentTime;
				openTime = numT;
			} else {
				if (preTime + numT > currentTime) {
					openTime -= (preTime + numT) - currentTime;
					openTime += numT;
					preTime = currentTime;
				} else {
					preTime = currentTime;
					openTime = numT;
				}
			}
			//			if (i != 0 && wk[i - 1] + numT > currentTime) {
			//				openTime -= (wk[i - 1] + numT) - currentTime;
			//				openTime += numT;
			//			} else {
			//				openTime = numT;
			//			}
			res += openTime;
		}

		out.println(res);
	}

C-Migration of ethnic groups

――It is better to always go to the city where you can go the most on that day ――Determine the day you can start (the very first day within the movable range) ――Go to the city you can go to that day (whether you go to a big city or a small city depends on the tribe) ――The next day's start is the city you are currently in --Create a pattern to move from a city with a small number to a city with a large number and a pattern from a large number to a small number.

	private void solveC() {
		int n = nextInt();
		int d = nextInt();
		int k = nextInt();

		int[][] aLR = Stream.generate(() -> new int[] { nextInt(), nextInt() }).limit(d).toArray(int[][]::new);
		//		int[][] aLR = IntStream.range(0, d).collect(() -> new int[d][2],
		//				(t, i) -> {
		//					t[i][0] = nextInt();
		//					t[i][1] = nextInt();
		//				}, (t, u) -> {
		//					Stream.concat(Arrays.stream(t), Arrays.stream(u));
		//				});
		int[][] aST = Stream.generate(() -> new int[] { nextInt(), nextInt() }).limit(k).toArray(int[][]::new);
		//		int[][] aST = IntStream.range(0, k).collect(() -> new int[k][2],
		//				(t, i) -> {
		//					t[i][0] = nextInt();
		//					t[i][1] = nextInt();
		//				}, (t, u) -> {
		//					Stream.concat(Arrays.stream(t), Arrays.stream(u));
		//				});

		for (int[] js : aST) {
			long day = getDay(aLR, js[0], js[1]);
			out.println(day);
		}

	}

	private long getDay(int[][] aLR, int start, int end) {
		int current = start;
		if (start < end) {
			for (int i = 0; i < aLR.length; i++) {
				if (aLR[i][0] <= current && current <= aLR[i][1]) {
					current = aLR[i][1];
				}
				if (current >= end) {
					return i + 1;
				}
			}
		} else {
			for (int i = 0; i < aLR.length; i++) {
				if (aLR[i][0] <= current && current <= aLR[i][1]) {
					current = aLR[i][0];
				}
				if (current <= end) {
					return i + 1;
				}
			}
		}

		return -1;
	}

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