0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ABC - 112- A&B&C

Posted at

AtCoder ABC 112 A&B&C

AtCoder - 112

A問題

	private void solveA() {
		int age = 0;

		age = Integer.parseInt(next());
		switch (age) {
		case 1:
			out.println("Hello World");
			break;
		case 2:
			int numA = nextInt();
			int numB = nextInt();
			out.println(numA + numB);
			break;
		}

	}

B問題

  • 時間$T_i$でソートして$T_i \leq T$の$C_i$を比較する
  • ソートした結果、一番低い$C_i$が解答
	private void solveB() {
		int numN = Integer.parseInt(next());
		int numT = Integer.parseInt(next());

		int[][] wk = new int[numN][2];

		for (int i = 0; i < wk.length; i++) {
			for (int j = 0; j < 2; j++) {
				wk[i][j] = nextInt();
			}
		}

		Arrays.sort(wk, (x, y) -> Integer.compare(x[1], y[1]));

		int cnt = 9999999;
		for (int i = 0; i < wk.length; i++) {
			if (wk[i][1] <= numT) {
				cnt = Math.min(wk[i][0], cnt);
			} else {
				break;
			}
		}

		out.println(cnt != 9999999 ? cnt : "TLE");
	}

C問題

  • $(x,y)$はそれぞれ100以下の整数なので総当りを試す
  • $(0,0),(1,0),(2,0) ・・・ (100,100)$
  • 総当りするために、基準となる場所 $(x_i,y_i)$ をピックアップする
    • 条件は
      • Hが0ではないものを選択する
        • 問題文 $max(H−|X−CX|−|Y−CY|,0) $ より、H=0のものはHが-または0の地点であるため。正確なHが算出できない。
	private void solveC() {
		int numN = Integer.parseInt(next());

		long[][] wk = new long[numN][3];

		for (int i = 0; i < numN; i++) {
			for (int j = 0; j < 3; j++) {
				wk[i][j] = nextLong();
			}
		}

		int referenceIndex = 0;
		//Hが-のものは0にされてしまっているため、Hが0でないものを基準にする必要がある。
		while (wk[referenceIndex][2] == 0) {
			referenceIndex++;
		}

		long h = -1;
		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j <= 100; j++) {
				boolean isRes = true;
				//0でないものを選択しているので、maxが不要
				h = Math.abs(wk[referenceIndex][0] - i) + Math.abs(wk[referenceIndex][1] - j) + wk[referenceIndex][2];
				for (int k = 0; k < numN; k++) {
					//Hが-のものは0に合わせてあるためmaxを入れないといけない
					if (wk[k][2] != Math.max(h - Math.abs(wk[k][0] - i) - Math.abs(wk[k][1] - j), 0)) {
						isRes = false;
						break;
					}
				}
				if (isRes) {
					out.println(i + " " + j + " " + h);
					return;
				}
			}
		}

	}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?