# UVa 808 (Build coordinate system, find law) Bee breeding

Source: Internet
Author: User

Test instructions

, numbering these squares according to the pattern in the diagram. The number of two squares is given, and the minimum number of steps from one lattice to another is obtained. (One step can only pass through a lattice with a common side)

Analysis:

According to high school mathematics knowledge, select any two non-collinear vector, it can represent all the points on the plane.

Set up a coordinate system like this, and calculate the coordinates of all points according to the rules in the diagram.

It's not hard to find the rules or the reasoning.

• The point in the first to third quadrant (x, y) is |x| from the origin. + |y|
• The point in the second to fourth quadrant (x, y) is max{|x|, |y|} from the origin.

The coordinates of the recurrence point is also more attention to detail, or it is easy to make mistakes.

`1#include <cstdio>2#include <cmath>3#include <algorithm>4 using namespacestd;5 Const intMAXN =10000;6 7 struct Point8 {9     intx, y;TenPoint (intx=0,inty=0): X (x), Y (y) {} One}P[MAXN + the]; A  - intDx[] = {-1, -1,0,1,1,0};//Six Directions - intDy[] = {0,1,1,0, -1, -1}; the intPos; -  - voidCalintDirintL//recursively pushes the coordinates of L-grids in dir direction - { +pos++; -      while(l--) +     { AP[pos] = Point (p[pos-1].x+dx[dir], p[pos-1].y+Dy[dir]); atpos++; -     } -pos--; - } -  - voidInit () in { -p[2] = Point (1, -1); topos =2; +      for(intL =1; L <= -; ++l) -     { the          for(intDIR =0; Dir <4; ++dir) * Cal (dir, l); \$Cal4, L +1);Panax NotoginsengCal5, L); -     } the } +  A intMain () the { + Init (); -  \$     intN, M; \$      while(SCANF ("%d%d", &n, &m) = =2&&N) -     { -         intx = p[n].x-p[m].x; the         inty = p[n].y-p[m].y; -         intans;Wuyi         if((x<0&&y>0) || (x>0&&y<0)) ans =Max (ABS (x), ABS (y)); the         ElseAns = ABS (x+y); -  Wuprintf"The distance between cells%d and%d are%d.\n", N, M, ans); -     } About  \$     return 0; -}`
code June

UVa 808 (Build coordinate system, find law) Bee breeding

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.