๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/PS

[๋ฐฑ์ค€] ํŠธ๋Ÿญ์ฃผ์ฐจ(2979), C++

by candosh 2024. 11. 11.

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

https://www.acmicpc.net/problem/2979

โœ๐Ÿป ๋ฌธ์ œ ์„ค๋ช…

๐Ÿ’๐Ÿป‍โ™€๏ธ ๋‚ด ํ’€์ด

์ด ๋ฌธ์ œ๋Š” A, B, C ์ƒํ™ฉ์„ ์ดํ•ดํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•˜๋‹ค. ๊ฐ๊ฐ A, B, C ์ƒํ™ฉ์„ ์˜ˆ์ œ๋กœ ๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

์ฒซ ๋ฒˆ์งธ 1๋ฒˆ์€ 1-6๊นŒ์ง€, 2๋ฒˆ์€ 3-5๊นŒ์ง€, 3๋ฒˆ์€ 2-8๊นŒ์ง€์ด๊ณ , 1๋Œ€์˜ ์ฐจ๋งŒ ์ฃผ์ฐจ๋˜์–ด ์žˆ๋Š” ์‹œ๊ฐ„์€ A, 2๋Œ€ ์‹œ๊ฐ„์—๋Š” B, 3๋Œ€ ์‹œ๊ฐ„ C์˜ ๊ฐ’์„ ๊ฐ๊ฐ ์ง€๋ถˆํ•˜๋ฉด ๋˜๋Š” ๊ฒƒ ์ด๋‹ค.

 

์ฃผ์˜ ํ•  ์ 

1. ๊ฐ ๊ตฌ๊ฐ„์˜ ์ง€๋ถˆ ๊ฐ’์€ ๊ฐ ์ฐจ๋งˆ๋‹ค ์ง€๋ถˆํ•˜๋Š” ๊ฐ’์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด B๊ตฌ๊ฐ„์˜ ๊ฒฝ์šฐ 1๋ถ„๋งˆ๋‹ค B์˜ ๊ฐ’์ด๊ณ  2๋Œ€๊ฐ€ ๊ฐ๊ฐ B๊ธฐ์ค€์œผ๋กœ ๊ฐ’์„ ์ง€๋ถˆํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ.

2. ์˜ˆ๋ฅผ ๋“ค์–ด 1-6์˜ ๊ฒฝ์šฐ 1์— ์˜ค๊ณ  6์— ๋– ๋‚œ ๊ฒƒ์ด๋‹ˆ 1์ด์ƒ 6๋ฏธ๋งŒ์œผ๋กœ ์ƒ๊ฐํ•ด์„œ ๊ณ„์‚ฐํ•ด์•ผ ํ•œ๋‹ค. ๋‚˜๋จธ์ง€ ์‹œ๊ฐ„๋„ ๋™์ผํ•˜๊ฒŒ ๊ณ„์‚ฐ.

 

A -> 3 -> 3*5 -> 15

B -> 2 -> 2*2*3 -> 12

C -> 2 -> 2*3*1 -> 6

 

15 + 12 + 6 = 33

 

๐Ÿค– ์ฝ”๋“œ

#include <iostream>
using namespace std;

int main()
{
	int arr[101] = {0,};
	int a, b, c, start, end, sum = 0;

	cin >> a >> b >> c;

	for (int i = 0; i < 3; i++)
	{
		cin >> start >> end;
		for (int i = start; i < end; i++)
		{
			arr[i]++;
		}
	}

	for (int i = 1; i <= 100; i++)
	{
		if (arr[i] == 1)
		{
			sum += a;
		}
		else if (arr[i] == 2)
		{
			sum += b * 2;
		}
		else if (arr[i] == 3)
		{
			sum += c * 3;
		}
	}

	cout << sum;

	return 0;
}