Title Link: Hdu 2177
This question is not the ordinary Nim game, I think it should be another game bar, and then push the SG function played a 20*20 table to see, in order to see some, I used color to mark, play the table code as follows:
1#include <cstdio>2#include <cstring>3#include <string>4#include <map>5#include <algorithm>6#include <windows.h>7 using namespacestd;8 9 intsg[103][103];Ten One intDfsintIintj) { A if(I >j) Swap (I,J); - if(Sg[i][j]! =-1|| Sg[j][i]! =-1) - returnSg[j][i] =Sg[i][j]; the - BOOL*vis =New BOOL[103]; - for(intg =0; G <103; ++g) -VIS[G] =0; + - for(intx =1; x <= i; ++x) +Vis[dfs (I-x, j)] = Vis[dfs (I-x, j-x)] =1; A for(inty =1; Y <= J; ++y) atVis[dfs (i, j-y)] =1; - - for(intg =0; ; ++g) { - if(!Vis[g]) { - Delete[] vis; - returnSg[j][i] = sg[i][j] =G; in } - } to } + -map<string, word>m; theInlinevoidinit () { *m["Blue"] =1|foreground_intensity; $m["Green"] =2|foreground_intensity;Panax Notoginsengm["Cyan"] =3|foreground_intensity; -m["Red"] =4|foreground_intensity; them["Pink"] =5|foreground_intensity; +m["Yellow"] =6|foreground_intensity; Am[" White"] =7|foreground_intensity; the } + -HANDLE Hconsole =GetStdHandle (std_output_handle); $ $InlinevoidSetColor (Const string&color) { - Setconsoletextattribute (Hconsole, M[color]); - } the - intMain () {Wuyi intb; thememset (SG,-1,sizeofSG); -sg[0][0] =0; Wu - init (); Aboutprintf" "); $SetColor ("Yellow"); - for(inti =0; I <= -; ++i) -printf"%2d", i); -Puts""); A for(inti =0; I <= -; ++i) { +SetColor ("Yellow"); theprintf"%2d", i); - for(intj =0; J <= -; ++j) { $ if(Dfs (i,j) = =0) SetColor ("Red"); the ElseSetColor (" White"); theprintf"%2d", DFS (I,J)); the } thePuts""); - } in thePuts""); theSetColor ("Cyan"); About for(inti =0; I <= -; ++i) the for(intj = i; J <= -; ++j) the if(Dfs (i,j) = =0) printf ("%d%d\n", i,j); theSetColor (" White"); + - return 0; the}
View Code
The results of the operation are as follows:
Do not see what the law, by Baidu, found that the original is Witzov, the final decision to use the Golden section of the number of what, but O (1) of the complexity, but Hangzhou electric This problem is also the output of the 1th step after the results of operation, that is, also to simulate, do not know how much of its data, Feel that the direct violence enumeration should be timed out, I would like to write a two points, but wrote a long time to write the more chaotic, so simply try the violence, unexpectedly seconds, the background data estimates are poor. The answer that needs to be output is no more than 3 groups, but for convenience, I still use vectors to save the answer that meets the requirements:
1#include <cstdio>2#include <cmath>3#include <Set>4#include <vector>5#include <cstdlib>6#include <algorithm>7 using namespacestd;8 Const intN =1000006;9 Const Doublep = (sqrt (5.0) +1) /2;Ten One BOOLOkintAintb) { A if(A >b) Swap ( A, a); - intK = B-A; - intc =intKp); the returnc = =A; - } - - intMain () { + intb; - while(~SCANF ("%d%d",&a,&b), a) { + if(A >b) Swap ( A, a); A if(OK (b)) puts ("0"); at Else { -Puts"1"); - for(inti =1; i < A; ++i) - if(OK (a-i, b-i)) printf ("%d%d\n", A-i, B-i); -vector<pair<int,int> >v; - for(inti =1; i < A; ++i) in if(OK (a-i, b)) V.push_back (Make_pair (A-I, b)); - for(inti =1; I < b; ++i) to if(OK (A, B-i)) { + if(A > B-i) v.push_back (Make_pair (b-I, a)); - ElseV.push_back (Make_pair (A, B-i)); the } * sort (V.begin (), V.end ()); $ intm = Unique (V.begin (), V.end ())-V.begin ();Panax Notoginseng for(inti =0; I < m; ++i) -printf"%d%d\n", V[i].first, v[i].second); the } + } A return 0; the}
View Code
Hdu 2177 (2 stacks) stone game (Witzov)