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

Last updated at Posted at 2019-03-22

AtCoder ABC 053 A&B&C

AtCoder - 053

A問題

1200未満と1200以上で分ければいいらしいです。


		int numN = nextInt();
		if (numN < 1200) {
			out.print("ABC");
		} else {
			out.print("ARC");
		}

B問題

文字列Sの中から先頭が"A"で始まり、"Z"で終わる部分文字列を探す。
探した部分文字列が最長となるときの長さを知りたい。

  • "A"で始まり"Z"で終わる文字列
    • Sの中で"A" を先頭から数えて一番始めの位置
    • Sの中で"Z" を後方から数えて一番初めの位置

で探せば、A-----Zという文字列の内、最長の文字列となるであろう。
○A○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○Z○
という感じ。
AとZの間は何でもいいし。


		String wk = next();

		int first = wk.indexOf("A");
		int last = wk.lastIndexOf("Z");

		String res = wk.substring(first, last + 1);

		out.println(res.length());

C問題

サイコロの面を動かして、合計x点を得るための最小手数。
手数を最小にする(x点を獲得するための最速)には、サイコロの最大値をとり続ければよいけど6をとり続けるわけにはいかないよね。と。
5と6を繰り返せばその時に選択できる値の最大値をとり続けることが出来るのでこれがよさげ。
最初に5でも6でも選択したことにして、「5→6→5→6→5→6→5→6→5」としたい。
5と6を行き来するということは、、、

  1. xを11(=5+6)で割る
  2. [1]の余りが6より大きいなら+2(6の面と5の面を1回ずつ)、小さいなら+1(6の面で解消)

でいける。
結局、開始が5なのか6なのかは、[1]の余りが6未満なら5から始めたことにすれば良いし、6以上ならどちらから始めても良い。となる。


		long numN = nextLong();

		long ope = 0;
		long opeNum = (numN / 11) * 2;
		int opeHasu = (numN % 11) == 0 ? 0 : (numN % 11) > 6 ? 2 : 1;
		ope = (opeNum + opeHasu);

		out.println(ope);
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?