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?

毎日ABC day14【c++】ABC332 A-C問題解説【ACコード付き】

Posted at

AtCoder Beginner Contest 332

A - Online Shopping

商品が $N$ 個あり、それぞれ価格 $P_{i}$ の商品を $Q_{i}$ 個購入する。購入した金額が $S$ 円以下の場合、 $K$ 円の送料がかかる。最終的に支払う金額はいくらか。

商品の合計について足し合わせ、送料がかかる場合かを判定して出力する。

int N, S, K;
int P[109];
int Q[109];

int main()
{
	cin >> N >> S >> K;
	int total_price = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> P[i] >> Q[i];
		total_price += P[i] * Q[i];
	}
	if (total_price < S) total_price += K;
	cout << total_price << endl;
	return 0;
}

B - Glass and Mug

容量が
$G$ ml のグラスと、容量が
$M$ ml のマグカップがある。以下の操作を $K$ 回行った後、それぞれ何mlずつ水が入っているか。

  • グラスが満たされていたら全部捨てる
  • グラス満タンでなく、マグカップが空だったらマグを水で満たす。
  • どちらでもない時は、マグが空になるかグラス満タンになるまでマグからグラスへ水を移動する。
int K, G, M;

int main()
{
	cin >> K >> G >> M;
	int c_grass = 0;
	int c_mag = 0;
	for (int i = 1; i <= K; i++)
	{
		if (c_grass == G) c_grass = 0;
		else if (c_mag == 0) c_mag = M;
		else
		{
			if (G - c_grass <= c_mag)
			{
				c_mag -= G - c_grass;
				c_grass = G;
			}
			else
			{
				c_grass += c_mag;
				c_mag = 0;
			}
		}
	}
	cout << c_grass << " " << c_mag << endl;
	return 0;
}

C - T-shirts

$N$ 日間、以下の3種類の予定がある時、最低何枚のロゴTシャツを持っていないといけないか。無地Tは $M$ 枚所持している。

  • ロゴTか無地Tを着る日
  • ロゴTを着る日
  • Tシャツを着ずに全て洗濯して再度着れる状態にする日

3つ目の洗濯の日に全てリセットされること、1つ目のロゴTか無地Tを着る日は優先して無地Tを着ることを気をつけていれば大丈夫。

int N, M;
string S;

int main()
{
	cin >> N >> M >> S;
	int num_muji = M;
	int num_logo = 0;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == '0')
		{
			num_muji = M;
			num_logo = 0;
		}
		else if (S[i] == '1')
		{
			if (num_muji > 0) num_muji--;
			else num_logo++;
		}
		else num_logo++;
		ans = max(ans, num_logo);
	}
	cout << ans << endl;
	return 0;
}
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?