https://www.acmicpc.net/problem/2869
2869번: 달팽이는 올라가고 싶다
첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000)
www.acmicpc.net
차근차근 슥슥 풀었으나, 시간초과가 발생한다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <functional>
#include <string>
using namespace std;
void fastIO();
int main()
{
int A, B, V;
int tmp = 0;
int day = 0;
cin >> A >> B >> V;
while (1)
{
++day;
tmp += A;
if (tmp >= V)
break;
tmp -= B;
}
cout << day;
}
void fastIO()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
식으로 푼다면 시간초과없이 정답으로나온다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <functional>
#include <string>
using namespace std;
void fastIO();
int main()
{
int A, B, V;
int day = 0;
cin >> A >> B >> V;
day = (V - B - 1) / (A - B) + 1;
cout << day;
}
void fastIO()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
나는 수학이 싫다.
그나저나 사람은 쉽게 변하지 않는다고
예전에도 이랬구나 ^^!
python 3 보다 pypy3 로 하게되면 더 빨라져서
날로먹으려다 실패한 흔적이 ㅋㅋ
'STUDY > Baekjoon' 카테고리의 다른 글
[백준] 2587 c++ 대표값2 (0) | 2023.03.14 |
---|---|
[백준] 2798 c++ 블랙잭 (0) | 2022.08.25 |
[백준] 1316 c++ 그룹 단어 체커 (0) | 2022.08.25 |
[백준] 25304 c++ 영수증 (0) | 2022.08.24 |
[백준] 2108 c++ 통계학 (0) | 2022.08.22 |