-
[백준] 2869 c++ 달팽이는 올라가고 싶다STUDY/C++, C#, VB6, PYTHON 2022. 8. 25. 03:56
https://www.acmicpc.net/problem/2869
차근차근 슥슥 풀었으나, 시간초과가 발생한다.
#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 > C++, C#, VB6, PYTHON' 카테고리의 다른 글
[백준] 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