POJ 1166 The Clocks (violent search), pojclocks
I found that I had no idea about this simulation problem. I was prepared to use bfs, but the result timed out. This was written by referring to other people's code:
# Include <stdio. h> # include <iostream> # include <algorithm> # include <set> # include <map> # include <vector> # include <math. h> # include <string. h ># include <queue >#include <string> using namespace std; int main () {int a [10], B [10], c [10]; freopen ("Release 6.in"," r ", stdin); for (int I = 1; I <= 9; I ++) scanf (" % d ", & a [I]); for (B [9] = 0; B [9] <= 3; ++ B [9]) for (B [8] = 0; B [8] <= 3; ++ B [8]) for (B [7] = 0; B [7] <= 3; ++ B [7]) for (B [6] = 0; B [6] <= 3; ++ B [6]) for (B [5] = 0; B [5] <= 3; ++ B [5]) for (B [4] = 0; B [4] <= 3; ++ B [4]) for (B [3] = 0; B [3] <= 3; ++ B [3]) for (B [2] = 0; B [2] <= 3; ++ B [2]) for (B [1] = 0; B [1] <= 3; ++ B [1]) {c [1] = (a [1] + B [1] + B [2] + B [4]) % 4; // The status of Clock 1 c [2] = (a [2] + B [1] + B [2] + B [3] + B [5]) % 4; // The status of clock 2 c [3] = (a [3] + B [2] + B [3] + B [6]) % 4; // The status c [4] = (a [4] + B [1] + B [4] + B [5] + B [7]) % 4; // status c [5] = (a [5] + B [1] + B [3] + B [5] + B [7] + B [9 ]) % 4; // The status c [6] = (a [6] + B [3] + B [5] + B [6] + B [9]) % 4; // The status c [7] = (a [7] + B [4] + B [7] + B [8]) % 4; // status c [8] = (a [8] + B [5] + B [7] + B [8] + B [9]) % 4 in 7 minutes; // status c [9] = (a [9] + B [6] + B [8] + B [9]) % 4; // if (c [1] + c [2] + c [3] + c [4] + c [5] + c [6] + c [7] + c [8] + c [9] = 0) // All positions: {for (int I = 0; I <B [1]; ++ I) printf ("1"); for (int I = 0; I <B [2]; ++ I) printf ("2"); for (int I = 0; I <B [3]; ++ I) printf ("3"); for (int I = 0; I <B [4]; ++ I) printf ("4"); for (int I = 0; I <B [5]; ++ I) printf ("5"); for (int I = 0; I <B [6]; ++ I) printf ("6"); for (int I = 0; I <B [7]; ++ I) printf ("7"); for (int I = 0; I <B [8]; ++ I) printf ("8"); for (int I = 0; I <B [9]; ++ I) printf ("9"); printf ("\ n ");}}}
Because yes
1 ABDE 2 ABC 3 BCEF 4 ADG 5 BDEFH 6 CFI 7 DEGH 8 GHI 9 EFHI
For the first minute, operations 1, 2, and 4 can change his status.
In this way, all operations are enumerated, and each operation will not exceed 4 times, because the effect of four operations is the same as that of zero operations.