Serie A champions:
There are three pieces all other pieces can jump cannot be separated by two jumps when asked state U for State v minimum short jump
Ideas:
For a state three pieces position can be set to X y Z (small to Large)
There are only two ways to jump when you are y-x=z-y, or Y to skip X or Y to skip Z.
The short side can jump many times when the equation is not true until the size relationship changes
So that's the structure of a two-fork tree. We will move Y to the left and right of the state as the original state of the son of the two sides to jump to the middle of the state as the original state of the father
Then the accessibility of the U and V becomes that they are not the same root so we can infer from the U and V jump to the head
Suppose you can jump a few times?? By using the LCA method and the multiplication method, you and V crawl to the same height and then crawl at the same time.
The method of crawling and the state of being moved to the root as well because there is no doubling of the table so the same depth we have to use the dichotomy to determine the height of the climb
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath>using namespace std;typedef unsigned long long LL; #define M 1100# Define N 16struct State {int x[3];void sort () {sort (x, x + 3);} int Root () {int floor = 0;int A1 = x[1]-x[0], a2 = x[2]-x[1];while (a1 = A2) {if (A1 > A2) {int d = (a1-1)/A2; Floor + = d;x[2]-= d * a2;x[1]-= d * A2;} else {int d = (a2-1)/A1;floor + d;x[0] + + D * a1;x[1] + = d * A1;} Sort (); a1 = X[1]-x[0], a2 = x[2]-x[1];} return floor;} BOOL operator== (const state FF) Const {return (x[0] = = Ff.x[0]) && (x[1] = = ff.x[1]) && (x[2] = = ff.x[2]); }void goup (int floor) {when (floor) {int a1 = x[1]-x[0], a2 = x[2]-x[1];if (A1 > A2) {int d = (a1-1)/a2;if (d > floor) d = Floor;floor = d;x[2]-= d * a2;x[1]-= d * A2; else {intD = (a2-1)/a1;if (d > Floor) d = Floor;floor = D;x[0] + = d * a1;x[1] + = d * A1;} Sort ();}}} U, V, FAU, Fav;int main () {int Fu, FV, Ans;while (~scanf ("%d%d%d%d%d%d", &u.x[0], &u.x[1], &u.x[2], &v.x[0 ] (&v.x[1],&v.x[2])) {u.sort (); V.sort (); FAU = U;fav = V;fu = FAU. Root (); fv = fav. Root (), if (FAU = = fav) {puts ("YES"), if (Fu > FV) {ans = fu-fv;u.goup (ans);} else if (FV > Fu) {ans = Fv-fu;v.gou P (ans);} Elseans = 0;int L = 0, r = min (Fu, FV), Mid, Tmp;while (L <= r) {mid = (L + r) >> 1;fau = U;fav = V;fau. Goup (mid); fav. Goup (mid), if (FAU = = fav) {r = Mid-1;tmp = Mid;} Elsel = mid + 1;} printf ("%d\n", ans + (tmp << 1));} Elseputs ("NO");} return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
HDU 3830 Checkers