๋ฌธ์
https://www.acmicpc.net/problem/20546
ํ์ด
์ฑ๋ฏผ(BNP)
- ๋จ์ ํ๊ธ์ผ๋ก ์ฃผ์์ ์ด ์ ์์ ๋๊น์ง ์ฃผ์ ๋งค์
์คํ(TIMING)
- 3์ผ ์ฐ์ ๊ฐ๊ฒฉ ์์น: ์ ๋ ๋งค๋
- 3์ผ ์ฐ์ ๊ฐ๊ฒฉ ํ๋ฝ: ์ ๋ ๋งค์
- ๋งค์ํ ๋๋ (์ฑ๋ฏผ๊ณผ ๋๊ฐ์ด) ๋จ์ ํ๊ธ์ผ๋ก ์ฃผ์์ ์ด ์ ์์ ๋๊น์ง ๋งค์
์ฝ๋
#include <iostream>
#include <vector>
using namespace std;
const int DAY = 14;
int bnp(int cash, vector<int> &price) {
int stock = 0;
for (int i = 0; i < DAY; i++) {
while (cash - price[i] >= 0) {
cash -= price[i];
stock++;
}
}
return stock * price[DAY - 1] + cash;
}
int timing(int cash, vector<int> &price) {
int stock = 0, up = 0, down = 0;
for (int i = 1; i < DAY; i++) {
// ๊ฐ๊ฒฉ ์์น, ํ๋ฝ ์ฒดํฌ
if (price[i - 1] < price[i]) { // ๊ฐ๊ฒฉ ์์น
up++;
down = 0;
} else if (price[i - 1] > price[i]) { // ๊ฐ๊ฒฉ ํ๋ฝ
down++;
up = 0;
} else { // ์ฃผ๊ฐ ๋์ผ
up = 0;
down = 0;
}
// ๋งค๋, ๋งค์
if (up == 3) { // 3์ผ ์ฐ์ ๊ฐ๊ฒฉ ์์น
while (stock) { // ์ ๋ ๋งค๋
cash += price[i];
stock--;
}
up = 0;
} else if (down == 3) { // 3์ผ ์ฐ์ ๊ฐ๊ฒฉ ํ๋ฝ
while (cash - price[i] >= 0) { // ์ ๋ ๋งค์
cash -= price[i];
stock++;
}
down = 0;
}
}
return stock * price[DAY - 1] + cash;
}
int main() {
int cash, bnp_result, timing_result;
vector<int> price(DAY, 0);
// ์
๋ ฅ
cin >> cash;
for (int &i: price) {
cin >> i;
}
// ์ฐ์ฐ
bnp_result = bnp(cash, price);
timing_result = timing(cash, price);
// ์ถ๋ ฅ
if (bnp_result > timing_result)
cout << "BNP";
else if (bnp_result < timing_result)
cout << "TIMING";
else
cout << "SAMESAME";
return 0;
}
'๐ญ Problem Solving' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][C++] ์คํฌํธ๋ฆฌ (0) | 2024.05.31 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][C++] ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2024.05.27 |
[ํ๋ก๊ทธ๋๋จธ์ค][C++] ์ฒด์ก๋ณต (0) | 2024.05.24 |
[BOJ][C++] ๋ฐฑ์ค 1212๋ฒ: 8์ง์ 2์ง์ (0) | 2024.05.24 |
[BOJ][C++] ๋ฐฑ์ค 9184๋ฒ: ์ ๋๋ ํจ์ ์คํ (0) | 2024.05.12 |