PS/BOJ
[백준] 15721. 번데기(c++)
backend 개발자 지망생
2024. 4. 27. 20:34
https://www.acmicpc.net/problem/15721
멋있게 풀고 싶었는데 쉽지 않았다.
구현 브루트포스 문제였다.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, t, target;
cin >> a >> t >> target;
int cnt1 = 0, cnt2 = 0, hu = -1;
int add = 2;
while (1) {
for (int i = 0; i < 2; i++) {
cnt1++, hu++;
if (target == 0 && cnt1 == t) {
cout << hu % a;
return 0;
}
cnt2++, hu++;
if (target == 1 && cnt2 == t) {
cout << hu % a;
return 0;
}
}
for (int i = 0; i < add; i++) {
cnt1++, hu++;
if (target == 0 && cnt1 == t) {
cout << hu % a;
return 0;
}
}
for (int i = 0; i < add; i++) {
cnt2++, hu++;
if (target == 1 && cnt2 == t) {
cout << hu % a;
return 0;
}
}
add++;
}
return 0;
}