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

Posted at

AtCoder ABC 060 A&B&C

AtCoder - 060

A問題

  • 文字Aの最後と文字B最初、文字Bの最後と文字Cの最後が同じならしりとりができる
  • 最初と最後はString#charAt()を使う
	private void solveA() {
		String strA = next();
		String strB = next();
		String strC = next();

		out.println(strA.charAt(strA.length() - 1) == strB.charAt(0)
				&& strB.charAt(strB.length() - 1) == strC.charAt(0) ? "YES" : "NO");

		out.println("");
	}

B問題

  • 余りには周期がある
  • 周期はBの数(割る数)分
  • $A1$ から $AB$ まで $mod5$ を繰り返す。

周期を表で記載

  • 余りは {$3,1,4,2,0$} を繰り返す
  • 余りの個数はB個 (割る数)
index A(の倍数) B C(の候補)
1 3 5 3
2 6 5 1
3 9 5 4
4 12 5 2
5 15 5 0
6 18 5 3
7 21 5 1
8 24 5 4
9 27 5 2

	private void solveB() {
		int numA = nextInt();
		int numB = nextInt();
		int numC = nextInt();

		if (numA == 1) {
			out.println("YES");
			return;
		}
		boolean res = false;
		for (int i = 1; i <= numB; i++) {
			res = (i * numA) % numB == numC;
			if (res) {
				break;
			}
		}

		out.println(res ? "YES" : "NO");
	}

C問題

  • 次の人がボタンを押下するまでの間の時間を調べる
    • シャワーの出る時間より長い場合
      • シャワーは最後まで出る
    • シャワーの出る時間より短い場合
      • シャワーは途中までで終わる(次のシャワーの時間が始まる)
    • 最後のシャワーは次の人がいないので時間いっぱい出る
	private void solveC2() {
		int numN = nextInt();
		long numT = nextInt();

		long[] wk = LongStream.range(0, numN).map(i -> nextLong()).toArray();

		//		long res = 0;
		//
		//		for (int i = 0; i < numN; i++) {
		//			if (i == numN - 1) {
		//				res += numT;
		//			} else {
		//
		//				if (wk[i + 1] - wk[i] >= numT) {
		//					res += numT;
		//				} else {
		//					res += wk[i + 1] - wk[i];
		//				}
		//
		//			}
		//		}
		long res = IntStream.range(0, numN).reduce(0, (sum, i) -> {
			if (i == numN - 1) {
				sum += numT;
				return sum;
			}
			if (wk[i + 1] - wk[i] > numT) {
				sum += numT;
			} else {
				sum += wk[i + 1] - wk[i];
			}
			return sum;
		});
		out.println(res);
	}

C問題:for版

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

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

		if (numN == 1) {
			out.println(numT);
			return;
		}

		wk[0][1] = wk[0][0] + numT > wk[1][0] ? wk[1][0] : numT;
		for (int i = 1; i < wk.length; i++) {
			if (i == wk.length - 1) {
				wk[i][1] = wk[i - 1][1] + numT;
				continue;
			}

			if (wk[i][0] + numT > wk[i + 1][0]) {
				wk[i][1] = (wk[i + 1][0] - wk[i][0]) + wk[i - 1][1];
			} else {
				wk[i][1] = numT + wk[i - 1][1];
			}

		}
		out.println(wk[numN - 1][1]);
	}
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?