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

AtCoder ABC 030 A&B&C AtCoder - 030

Ein Problem

	private void solveA() {
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();
		int d = nextInt();
		if (b * c > a * d) {
			out.println("TAKAHASHI");
		} else if (b * c < a * d) {
			out.println("AOKI");
		} else {
			out.println("DRAW");
		}
	}

B Problem

--Mendoi berechnet den Winkel des Stundenzeigers der Uhr

	private void solveB() {
		int n = nextInt();
		int m = nextInt();

		double smallHand = n % 12 * 30 + m * 0.5;//n % 12 * (360 / 12) + m * (360 / 12 /  60)
		double longHand = m % 60 * 6;//m % 60 * (360 / 60)

		double res = Double.max(smallHand, longHand) - Double.min(smallHand, longHand);
		/*
		 * 23:10 ist größer als 180
		 */
		if (res > 180) {
			out.println(360 - res);
		} else {
			out.println(res);
		}
	}

Problem C: Dichotomie

	private void solveC2() {
		int n = nextInt();
		int m = nextInt();
		long x = nextInt();
		long y = nextInt();
		long[] aA = LongStream.range(0, n).map(i -> nextLong()).toArray();
		long[] bA = LongStream.range(0, m).map(i -> nextLong()).toArray();

		/*
		 * true = airport A
		 * false = airport B
		 */
		boolean isAirportA = true;
		long currentTime = 0;
		long moveCnt = 0;
		while (true) {
			/*
			 *Abflug vom Flughafen A oder Abflug vom Flughafen B.
			 */
			if (isAirportA) {
				/*
				 *Suchen Sie einen Flug am Flughafen A, der von der aktuellen Zeit abfliegen kann
				 */
				int aI = Arrays.binarySearch(aA, currentTime);
				aI = aI >= 0 ? aI : ~aI;
				//Wenn Sie nach zwei Minuten suchen und die letzte Indexposition erreichen, ist diese bereits beendet
				if (aI >= n) {
					break;
				}
				/*
				 *Zeit zum Abflug vom nächsten B-Flughafen
				 */
				currentTime = aA[aI] + x;
				/*
				 *Weiter ist B Flughafen
				 */
				isAirportA = false;
				moveCnt++;
			} else {
				/*
				 *Der Inhalt ersetzt lediglich alle Werte des Flughafens A durch B.
				 */
				int bI = Arrays.binarySearch(bA, currentTime);
				bI = bI >= 0 ? bI : ~bI;
				if (bI >= m) {
					break;
				}
				currentTime = bA[bI] + y;
				isAirportA = true;
				moveCnt++;
			}
		}
		/*
		 *X, wenn die Anzahl der Bewegungen ungerade ist->Ich bin gerade zu Y gegangen
		 *Ich konnte keine Rundreise machen.
		 *Daher ist die Bewegung dieser Zeit Birne
		 */
		if ((moveCnt & 1) == 1) {
			moveCnt -= 1;
		}
		/*
		 *Die Häufigkeit, mit der die Hälfte der Anzahl der Personen im Flugzeug eine Rundreise unternehmen konnte
		 */
		out.println(moveCnt / 2);

	}

Problem C: Eine andere Lösung (nur bestimmt durch für, ohne Dichotomie)

――Ich konnte eine Dichotomie entwickeln und sie sofort implementieren, aber sie ist irgendwie schmutzig. Wenn ich also nach einer anderen Methode suchte, hatte ich das Gefühl, dass ich sie auch hier implementieren könnte, also habe ich es versucht. ―― Anstatt jedes Mal nach allen $ A [i] und B [i] $ zu suchen, sollten Sie beide Arrays einfach einmal drehen, wenn Sie den Index in der Mitte halten. Die Idee

--Finden Sie die Abflugzeit eines Flughafens

	/*
	 *Volle Suche?
	 */
	private void solveC() {
		int n = nextInt();
		int m = nextInt();
		long x = nextInt();
		long y = nextInt();
		long[] aA = LongStream.range(0, n).map(i -> nextLong()).toArray();
		long[] bA = LongStream.range(0, m).map(i -> nextLong()).toArray();

		int bI = 0;
		long currentTime = 0;
		long moveCnt = 0;
		for (int i = 0; i < n; i++) {
			//Abfahrtszeiten, die kleiner als die aktuelle Zeit sind, können nicht verwendet werden
			if (currentTime > aA[i]) {
				continue;
			}
			//Kann von einem Flughafen abfliegen
			currentTime = aA[i] + x;
			//Beginnen Sie am Flughafen B nach Zeit zu suchen
			for (int j = bI; j < m; j++) {
				//Abfahrtszeiten, die kleiner als die aktuelle Zeit sind, können nicht verwendet werden
				if (currentTime > bA[j]) {
					continue;
				}
				/*
				 *Diese Zeit kann also genutzt werden
				 *・ Stellen Sie die Abflugzeit des nächsten A-Flughafens ein
				 *・ Legen Sie den Index für den Start der Zeitsuche für den nächsten B-Flughafen fest
				 */
				currentTime = bA[j] + y;
				bI = j + 1;
				//Ich konnte Flughafen B verlassen und eine Rundreise machen
				moveCnt++;
				break;
			}
		}
		out.println(moveCnt);
	}

Recommended Posts

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 - 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.
ABC - 131 - A & B & C & D & E.
diverta 2019 Programmierwettbewerb A & B & C & D.
AtCoder Anfängerwettbewerb 169 A, B, C mit Rubin
atcoder ABC113 C Problem
atcoder ABC115 C Problem
AtCoder Anfängerwettbewerb 170 A, B, C bis Rubin
Machen Sie einen SOAP-Aufruf in C #
Rufen Sie C-Sprachfunktionen von Swift aus auf
NLP4J 100 Sprachverarbeitungsklopfen mit NLP4J # 34 "A B"