1
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 - 061 - A&B&C

Posted at

AtCoder ABC 061 A&B

AtCoder - 061

A問題

  • こういうのって思考速度にタイピング速度がついてくるかどうかで分かれるよな
	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();
		int numC = nextInt();

		out.println(numC >= numA && numC <= numB ? "Yes" : "No");

	}

B問題

Map使ってカウントしてもいいけど、配列操作に慣れたいので配列で実装

  • [4 3]となっている場合、以下の様に算出
    • 4は3に向かって道路が延びているので+1
    • 3は4に向かって道路が延びているので+1
	private void solveB() {
		int numN = nextInt();
		int numM = nextInt();

		int[] wk = new int[numN];

		for (int i = 0; i < numM; i++) {
			int a = nextInt();
			int b = nextInt();
			wk[a - 1]++;
			wk[b - 1]++;
		}

		Arrays.stream(wk).forEach(i -> out.println(i));
	}

C問題

はまった問題。

何も考えずに問題どおりだと・・

  • 1,5,2,4,3となっている場合
    • {1,22,333,4444,5555}という配列を作成
    • その配列のK番目の値を取得する

こんな配列作れないので、単純な足し算に置換

private void solveC() {
		int numN = nextInt();
		long numK = nextLong();

		int[][] wk = new int[numN][2];
		for (int i = 0; i < numN; i++) {
			wk[i][0] = nextInt();
			wk[i][1] = nextInt();
		}

		/**
		 * a_1 - a_i までがsortされているとは書いてないよね。。。
		 * なので、sort必須。sortしないとWAです。
		 * はまったわーーー
		 */
		Arrays.sort(wk, (a, b) -> Integer.compare(a[0], b[0]));

		long sum = 0;
		for (int i = 0; i < wk.length; i++) {
			sum += wk[i][1];
			if (sum >= numK) {
				out.println(wk[i][0]);
				return;
			}
		}

	}

1
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
1
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?