알고리즘 연습/백준
[C++][BOJ17248] ceil 소숫점 올림
_h.j
2021. 7. 1. 17:55
728x90
https://www.acmicpc.net/problem/17248
17248번: 물리 공부
A 자동차는 20m/s로, B 자동차는 60m/s로 달리고 있을 때 A의 속도가 크기 2의 가속도에 의해 1초에 22m/s, 2초에 26m/s, 3초에 32m/s ... 로 증가 하게 되어서 A의 속도가 6초에 62m/s가 된다.
www.acmicpc.net
경북대 2019 프로그래밍 경시대회 문제
문제 풀이
단순 수학 계산 문제다.
소스 코드
#include <bits/stdc++.h>
using namespace std;
int X,Y,Z;
float answer;
void Input(){
cin>>X>>Y>>Z;
}
void Solution(){
answer = (-1*Z + sqrt( Z*Z - 4 *Z*(2*X - 2 * Y ) ) ) / (2.0 * (float)Z );
cout<<ceil(answer)<<"\n";
}
void Slove(){
int T;
cin>>T;
while(T--){
Input();
Solution();
}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
Slove();
return 0;
}
ceil
소숫점 올림 함수
728x90