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

AtCoder ABC 026 A&B&C AtCoder - 026

--ABC027 Ich war wirklich besorgt, aber der Schwierigkeitsgrad ist sehr unterschiedlich.

Ein Problem

-Versuchen Sie alle Kombinationen von $ (x, y) $

	private void solveA() {
		final int a = nextInt();
		int res = IntStream.range(1, a).reduce(0, (sum, i) -> Integer.max(i * (a - i), sum));

		out.println(res);
	}

B Problem

--Malen Sie von außen von rot nach weiß

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

		long res = 0;
		boolean isRed = true;
		for (int i = 0; i < wk.length; i++) {
			res += Math.pow(wk[numN - 1 - i], 2) * (isRed ? 1 : -1);
			isRed = !isRed;
		}
		double mul = res * Math.PI;
		out.println(mul);
	}

C-Problem: Klassenverwendung

――Es ist überflüssig, aber ich habe eine Klasse erstellt, um mein Gehalt auszudrücken ――Was ist BOSS, obwohl Sie Ihr Gehalt ausdrücken? .. ..

	private void solveC() {
		int numN = nextInt();
		/*
		 * Index=0 -> B2
		 * Index=-1 -> B1
		 */
		int[] wk = IntStream.range(0, numN - 1).map(i -> nextInt()).toArray();

		/*
		 *Untergeordnete Liste
		 */
		Boss[] wkList = new Boss[numN - 1];
		/*
		 *Nur für Takahashi
		 */
		Boss takahashi = new Boss();
		/*
		 *Wenn Sie es von Ende an ausführen, haben Sie immer einen Chef. richtig?
		 * (Takahashi schließt seinen Chef aus)
		 */
		for (int i = wk.length - 1; i >= 0; i--) {
			/*
			 *Holen Sie sich Ihr eigenes Gehalt
			 */
			int salary = getSelfSalary(wkList, i);

			/*
			 *Passen Sie die Bossnummer und den Index an
			 *Wenn Takahashi ein Boss ist-Werden Sie 1
			 */
			int bossNum = wk[i] - 2;
			/*
			 *Holen Sie sich eine Liste der Untergebenen des Chefs
			 *Tragen Sie Ihr Gehalt in die Liste Ihres Chefs ein (gesamt?)
			 */
			if (bossNum == -1) {
				/*
				 *BOSS ist Takahashi, also Gehalt+
				 *Auch in Takahashi, max und min+Weil die Einschränkung 1 angewendet wird
				 */
				takahashi.setMax(salary);
				takahashi.setMin(salary);
				takahashi.addMembers(1);
			} else {
				Boss boss = wkList[bossNum];
				if (boss == null) {
					/*
					 *Registriert als Chef, der bis jetzt keine Untergebenen hatte
					 */
					boss = new Boss();
					wkList[bossNum] = boss;
				}
				boss.setMax(salary);
				boss.setMin(salary);
				boss.addMembers(1);
			}

		}

		out.println(takahashi.getMax() + takahashi.getMin() + 1);
	}

	/**
	 *Holen Sie sich Ihre untergeordnete Liste,
	 *Meine Gehaltsabrechnung
	 * @param wkList
	 * @param i
	 * @return
	 */
	private int getSelfSalary(Boss[] wkList, int i) {
		int salary;

		Boss self = wkList[i];
		if (self != null) {
			int min = self.getMin();
			int max = self.getMax();
			salary = max + min + 1;
		} else {
			salary = 1;
		}
		return salary;
	}

	/**
	 *Mit der Anzahl meiner Untergebenen
	 *Halten Sie das Maximum und Minimum Ihres Gehalts
	 * @author works
	 *
	 */
	private static class Boss {
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		int members;

		public int getMembers() {
			return members;
		}

		public void addMembers(int member) {
			this.members += member;
		}

		public int getMin() {
			return min;
		}

		public int getMax() {
			return max;
		}

		public void setMin(int min) {
			this.min = Integer.min(this.min, min);
		}

		public void setMax(int max) {
			this.max = Integer.max(this.max, max);
		}
	}

C Problem: Liste

Ich habe mit Klasse berechnet, aber Sie können es auch mit dieser Liste tun, oder? ?? ?? Ich dachte, ich habe versucht, es in List auszudrücken.

Es war viel schneller als der Unterricht

	private void solveC2() {
		int numN = nextInt();
		/*
		 * Index=0 -> B2
		 * Index=-1 -> B1
		 */
		int[] wk = new int[numN + 1];
		List<List<Integer>> mems = new ArrayList<List<Integer>>();
		wk[0] = 0;
		wk[1] = 0;
		mems.add(new ArrayList<Integer>());
		mems.add(new ArrayList<Integer>());
		for (int i = 0; i < numN - 1; i++) {
			wk[i + 2] = nextInt();
			mems.add(new ArrayList<Integer>());
		}

		for (int i = wk.length - 1; i >= 0; i--) {
			List<Integer> tmp = mems.get(i);
			int salary = 0;
			if (tmp.size() != 0) {
				int min = Integer.MAX_VALUE;
				int max = Integer.MIN_VALUE;
				for (int j = 0; j < tmp.size(); j++) {
					min = Integer.min(min, tmp.get(j));
					max = Integer.max(max, tmp.get(j));
				}
				salary = min + max + 1;
			} else {
				salary = 1;
			}
			tmp = mems.get(wk[i]);
			tmp.add(salary);
		}
		long salary = 0;
		{
			List<Integer> tmp = mems.get(1);
			int min = Integer.MAX_VALUE;
			int max = Integer.MIN_VALUE;
			for (int j = 0; j < tmp.size(); j++) {
				min = Integer.min(min, tmp.get(j));
				max = Integer.max(max, tmp.get(j));
			}
			salary = min + max + 1;
		}
		out.println(salary);
	}

Recommended Posts

ABC - 013-A & B & C.
ABC - 023 - A & B & C.
ABC - 010 - A & B & C.
ABC - 028 - A & B & C.
ABC - 015 - A & B & C.
ABC - 128 - 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 - 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
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"