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 |
规律很好找每个数有三个坐标,横向和两条斜边,自己找出坐标的规律即可,答案是两个数所有坐标差的绝对值之和。 #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator