U E D R , A S I H C RSS

Steps/문보창

소감

2006-01-08 Accepted 0.012 Minimum
A, B 라는 입력이 들어왔을 때, n = B - A 로 본다면, n = 1 ~ 20 {1,2,3,3,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,8}. 간단한 일차 방정식 작성으로 풀 수 있다.

코드

~cpp
// 846 - Steps
#include <iostream>
using namespace std;
#include <cmath>

inline void process(int n)
{
	int i = floor(sqrt(n));
	for (; i * (i + 1) <= n; i++) ;
	if (n == i * (i - 1)) 
		cout << 2 * (i - 1) << endl;
	else if (n <= i * i) 
		cout << 2 * i - 1 << endl;
	else 
		cout << 2 * i << endl;	
}

int main()
{
	int nCase, x, y;
	cin >> nCase;
	for (int i = 0; i < nCase; i++)
	{
		cin >> x >> y;
		process(y - x);
	}
	return 0;
}
----
Steps
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:07
Processing time 0.0086 sec