A * \ IDA * analysis summary and ida analysis summary
Classic eight queens question:
# Include <iostream> # include <algorithm> # include <queue> # include <vector> # include <cstdio> # include <cstring> using namespace std; struct node {int tab [3] [3]; int r, c; int hash_val; // node * pre; int op; int f, g; // f: Estimated value g: bool operator consumed from the start point to the current point <(const node & rhs) const {return f> rhs. f ;}} st, ed; node t [370000]; int tot; int hash_tab [370000]; priority_queue <node> open; int fn [10]; int ed_m Ap [10] [2]; int dir_ I [4] = {0, 1,-1}; int dir_j [4] = {1,-1, 0 }; char print_op [4] = {'R', 'l', 'D', 'U'}; // process the input character void In (char s [], node & t) {char ch; int next = 0; for (int I = 0; I <3; ++ I) {for (int j = 0; j <3; ++ j) {while (s [next] = '') ++ next; ch = s [next ++]; if (isdigit (ch) st. tab [I] [j] = ch-'0'; location of else {// x st. r = I; st. c = j; st. tab [I] [j] = 0 ;}}// obtain the estimated function value int get_f (node a, int g) {int h = 0; For (int I = 0; I <3; ++ I) for (int j = 0; j <3; ++ j) if (. tab [I] [j]) // distance from the target's Manhattan h + = abs (I-ed_map [. tab [I] [j] [0]) + abs (j-ed_map [. tab [I] [j] [1]); return g + h;} // expand a conutation to determine the position of the combination in all the arrays: int get_hash (node) {int ret; ret = 0; int num = 8; for (int I = 0; I <3; ++ I) {for (int j = 0; j <3; ++ j) {int x = 0; // The number of smaller ones after the current number for (int jj = j + 1; jj <3; ++ jj) if (. tab [I] [jj] <. tab [I] [j]) x ++; for (int ii = I + 1; ii <3; ++ ii) for (int jj = 0; jj <3; ++ jj) if (. tab [ii] [jj] <. tab [I] [j]) x ++; ret + = fn [num] * x; // expand num -- ;}} return ret ;} // pre-processing void init () {memset (hash_tab, 0, sizeof (hash_tab); while (! Open. empty () open. pop (); tot = 0; st. f = get_f (st, 0); // obtain the estimated function value st. g = 0; st. hash_val = get_hash (st); // obtain the position in the full array of open. push (st); hash_tab [st. hash_val] = 1; // The current composite arrangement has been traversed} void pre () {// preprocessing factorial fn [0] = 1; for (int I = 1; I <9; ++ I) fn [I] = I * fn [I-1]; // preprocessing result for (int I = 0; I <3; ++ I) for (int j = 0; j <3; ++ j) ed. tab [I] [j] = (I * 3) + j + 1; ed. tab [2] [2] = 0; ed. hash_val = get_hash (ed); // position of the pre-processing result Ing for (int I = 0; I <3; ++ I) for (int j = 0; j <3; ++ j) if (ed. tab [I] [j]) {ed_map [ed. tab [I] [j] [0] = I; ed_map [ed. tab [I] [j] [1] = j ;}// judge the parity of the number of reverse orders int get_preval (node a) {int ret = 0; for (int I = 0; I <3; ++ I) for (int j = 0; j <3; ++ j) {if (! A. tab [I] [j]) continue; int x = 0; for (int jj = j + 1; jj <3; ++ jj) if (. tab [I] [jj] &. tab [I] [jj] <. tab [I] [j]) x ++; for (int ii = I + 1; ii <3; ++ ii) for (int jj = 0; jj <3; ++ jj) if (. tab [ii] [jj] &. tab [ii] [jj] <. tab [I] [j]) x ++; ret + = x;} return ret & 1;} bool pre_solve () {return (get_preval (st) ^ (get_preval (ed);} void change (node & tmp, node a, int nextr, int nextc, int _ I, int idx) {for (int I = 0; I <3; ++ I) for (int j = 0; j <3; ++ j) tmp. tab [I] [j] =. tab [I] [j]; swap (tmp. tab [nextr] [nextc], tmp. tab [. r] [. c]); tmp. hash_val = get_hash (tmp); tmp. r = nextr; tmp. c = nextc; tmp. pre = & t [idx]; tmp. op = _ I; // move to tmp. g =. g + 1; // The current step tmp. f = get_f (tmp, tmp. g);} bool check (int I, int j) {if (I> 2 | I <0 | j> 2 | j <0) return false; return true;} // print the path void path (node * a) {if (a-> hash_val = st. has H_val) return; path (a-> pre); printf ("% c", print_op [a-> op]);} // A * void Astar () {int nextr, nextc; node ans = st; int fla = 0; if (st. hash_val! = Ed. hash_val) while (! Open. empty () {node a = open. top (); open. pop (); t [++ tot] = a; for (int I = 0; I <4; ++ I) {nextr =. r + dir_ I [I]; nextc =. c + dir_j [I]; if (check (nextr, nextc) {node tmp; change (tmp, a, nextr, nextc, I, tot ); if (hash_tab [tmp. hash_val]) continue; if (tmp. hash_val = ed. hash_val) {fla = 1; ans = tmp; break;} open. push (tmp) ;}} if (fla) break; hash_tab [. hash_val] = 1;} path (& ans); puts ("");} int main () {// freopen ("Input.txt", "r", stdin ); char ss [12]; while (gets (ss) {pre (); In (ss, st); init (); if (pre_solve ()) puts ("unsolvable"); else Astar ();} return 0 ;}
For shifts left or right of spaces (0), the corresponding sequence remains unchanged (the number of reverse orders remains unchanged)
For a move-up/move-down operation with spaces (0), it is equivalent to moving two digits forward/backward in a sequence. The odd number of reverse orders of the sequence remains unchanged.
Therefore, you can determine the number of reverse orders between the initial State and the target State.
In this example, the former is odd, and the latter is even, so there is no solution.
There is no solution to the given initial State using parity.
The discriminant method is as follows:
Take an array as one-dimensional example.
A node of octal digital is represented as an array a [9], and a space is represented by 0. The temporary FUNCTION p (x) is defined: the number before the position where x is located is smaller than x,
Where 0 spaces are not included, the set target State is B [9], then r = sigma (p (x) sigma () indicates to take all x: 1-8 and sum,
For the initial state a [9], t = sigma (p (x), if r and t are both odd or even, the state is resolved. Otherwise, no solution is available.
Considering the influence of the Four moving methods on sigma (p (x), the left shift and right shift will not affect its value,
It will not affect parity. If it is a move up or move down, it will affect:
Move up: a move up will jump an element to the position of two numbers, set the two numbers to a1, a2,
Set a1 <a2, and set the number to a0. There are only three situations:
1, a0 <a1 <a2, consider the p (x) values of the three, p (a0) unchanged, p (a1) ++, p (a2) ++, an increase of 2
2, a1 <a0 <a2, p (a0) --, p (a1) unchanged, p (a2) ++, overall unchanged
3, a1 <a2 <a0, p (a0)-= 2, p (a1), p (a2) remain unchanged, and the overall decrease is 2
The conclusion is that sigma (p (x) is not affected.
Summary Analysis Method of combined Logic Circuit
The basic method is to list the truth tables to produce the simplest and simplest form of the Kano diagram, so that two levels of and non-gate implementation can be used. (And or form can be written into two levels and non-Forms)
Returns the inverse of the variable X Using X + Y = (X 'y ')'
Set the number of adders to A1A0, B1B0, D1D0, and C:
D1 = A1 'a0 'b1 + a1' b1b0' + A1 'a0b1 'b0 + A1A0B1B0 + A1A0 'b1'
+ A1B1 'b0'
= (A1 'a0 'b1) '(A1 'b1b0')' (A1 'a0b1 'b0') '(A1A0B1B0)' (A1A0 'b1 ') '(A1B1 'b0 ')')'
D0 = A0 'b0 + a0b0' = (A0 'b0) '(a0b0 ')')'
C = A1B1 + A1A0B0 + A1B1B0 = (A1B1) '(A1A0B0)' (A1B1B0 )')'
In this way, it is available and non-door implementation.
The summary is generally to summarize the practice activities of the unit or individual. Therefore, the summary mainly uses the first-person writing (A) to (B) error.
Summary: it is a written review and analysis of the work, study, or ideological situation in the past period, and provides an objective evaluation. By content, including study summary, work summary, and thought summary, by time, annual summary, quarterly summary, and month summary.
Pair