| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
主要是规律 附代码计算差的绝对值
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator