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

主要是规律 附代码

Posted by mickeyandkaka at 2010-11-13 23:58:55 on Problem 2590
计算差的绝对值
1  1
2  2
3~4  3
5~6  4
7~9  5
。。。
右侧的数用递推
a1=1
an-a1=(i+1)/2(2<=i<=n)的和;
返回i的值

#include <stdio.h>
#include <stdlib.h>
int fun(int n);
int main()
{
	int i,n,a,b;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&a,&b);
		printf("%d\n",fun(abs(b-a)));
	}
	return 0;
}
int fun(int n)
{
	int i,a=1;
	if(n==1) return 1;
	else if(n==0) return 0;
	else
	{
		for(i=2;;i++)
		{
			a+=(i+1)/2;
			if(a>=n) break;
		}	
	}
	return i;	
}

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