Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0ms 水过

Posted by fbioki at 2012-03-17 09:47:11 on Problem 2590
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <set>

using namespace std;

const double  eps = (1e-9);

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	int t, n, m;
	int d, ans, k;
	scanf("%d", &t);
	while(t --)
	{
		scanf("%d%d", &n, &m);
		if(n == m) { printf("0\n"); continue; }
		d = m - n;
		k = int(floor(sqrt(1.0*d))-eps)+1;
		ans = k + k - 1;
		d = d - k * k;
		if(!d) printf("%d\n", ans);
		else if(d > k) printf("%d\n", ans + 2);
		else printf("%d\n", ans + 1);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator