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

AtCoder ABC 024 A&B&C AtCoder - 024

2019/05/27 Korrektur des Problemnamens Es wurde behoben, wie C-Problemcode einen Teil von int [] [] `` generiert wurde

Ein Zoo

――Wenn Sie nach der Addition einen Rabatt erhalten, können Sie vorerst einen Rabatt gewähren

	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-Automatische Tür

――Ich kann keine Erklärung für die Lösung bekommen. .. ..

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

――Es ist besser, immer in die Stadt zu gehen, in die Sie an diesem Tag am meisten gehen können ――Bestimmen Sie den Tag, an dem Sie beginnen können (der allererste Tag innerhalb des beweglichen Bereichs). ――Gehen Sie in die Stadt, die Sie an diesem Tag besuchen können (ob Sie in eine große oder eine kleine Stadt gehen, hängt vom Stamm ab) ――Der nächste Tag beginnt in der Stadt, in der Sie sich befinden --Erstellen Sie ein Muster, um von einer Stadt mit einer kleinen Zahl zu einer Stadt mit einer großen Zahl und einem Muster von einer großen Zahl zu einer kleinen Zahl zu wechseln.

	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 Programmierwettbewerb A & B & C & D.
AtCoder Anfängerwettbewerb 169 A, B, C mit Rubin
ABC093 C - Gleiche Ganzzahlen
atcoder ABC115 C Problem
AtCoder Anfängerwettbewerb 170 A, B, C bis Rubin
Eine Person, die C ++ schreibt, hat versucht, Java zu schreiben
Machen Sie einen SOAP-Aufruf in C #
Rufen Sie C-Sprachfunktionen von Swift aus auf
NLP4J 100 Sprachverarbeitungsklopfen mit NLP4J # 34 "A B"