2756: [SCOI2012] Strange game time limit:40 Sec Memory limit:128 MB
submit:3352 solved:919
[Submit] [Status] [Discuss] Description
Blinker recently enjoyed a strange game.
This game is played on a n*m board with a number per grid. Each blinker will select two adjacent
Grid and add 1 to these two numbers.
Now blinker want to know at least how many times you can make the number on the board become the same number, if you can never become the same
A number is output-1.
Input
The first line of input is an integer t, which indicates that the input data has a T-wheel game composition.
The first line of each game has two integers n and m, each representing the number of rows and columns of the chessboard.
Next there are n rows, and the number of m per line.
Output
For each game output the minimum number of times the game will end, if you can never become the same number output-1.
Sample Input2
2 2
1 2
2 3
3 3
1 2 3
2 3 4
4 3 2Sample Output2
-1
HINT
"Data Range"
For 30% of data, ensure t<=10,1<=n,m<=8
For 100% of data, guaranteed t<=10,1<=n,m<=40, all numbers are positive integers and less than 1000000000
A typical chessboard
Black-and-white staining, white lattice CB, numbers and for SB;
Set the last number to X, operate the T-time, each operation must be a black lattice a white lattice
Cb*x=sb+t
Cw*x=sw=t
Solution to X= (SB-SW)/(CB=CW)
Category discussion:
1.CB!=CW get x, Judge the Law (X>=MX) on the line
2.CB==CW (this time must be n,m are even), X is not sure
(1) SB!=SW no solution
(2) SB==SW two x is how much, find the smallest legal x
How to judge an X to be legal:
Black-and-white dyeing is a two-part picture
s--and X Difference---black lattice--inf--> white lattice--and X difference value-->t
Attention:
Do not put M into N don't put M into N don't put M into N don't put M into n don't turn m into N don't put M. into the n do not play M into n
There's a lot of places ah ah ah ah ah oh ah ah ah
Bzoj 2756: [SCOI2012] Strange game [Max Stream binary]