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 15211160230 at 2017-02-12 15:09:45 on Problem 2619
每个数有三个坐标,横向和两条斜边,自己找出坐标的规律即可,答案是两个数所有坐标差的绝对值之和。
#include <cstdio>
#include <cmath>
using namespace std;
inline int CalX(int N){
	int w=(int)sqrt(1.0*N);
	if(w*w==N)	return w;
	else 		return w+1;
}
inline int CalY(int N,int n){ 
	return (N-(n*n-2*n+2))/2+1;
}
inline int CalZ(int N,int n){
	return (n*n-N)/2+1;
}
inline int Abs(int N){
	return N>=0?N:-N;
}
struct Coord{
	int x,y,z;
};
int main()
{	int N,M,sum;
	Coord X,Y;
	while(~scanf("%d %d",&N,&M))
	{	X.x=CalX(N),Y.x=CalX(M);
		X.y=CalY(N,X.x),Y.y=CalY(M,Y.x);
		X.z=CalZ(N,X.x),Y.z=CalZ(M,Y.x);
		sum=Abs(X.x-Y.x)+Abs(X.y-Y.y)+Abs(X.z-Y.z);
		printf("%d\n",sum);
	}
    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