hdu 3683-gomoku-模拟-[解题报告]hoj

Gomoku

问题描述 :

You are probably not familiar with the title, “Gomoku”, but you must have played it a lot. Gomoku is an abstract strategy board game and is also called Five in a Row, or GoBang. It is traditionally played with go pieces (black and white stones) on a go board (19×19 intersections). Nowadays, standard chessboard of Gomoku has 15×15 intersections. Black plays first, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five or more stones horizontally, vertically, or diagonally.

For convenience, we coordinate the chessboard as illustrated above. The left-bottom intersection is (0,0). And the bottom horizontal edge is x-axis, while the left vertical line is y-axis.

I am a fan of this game, actually. However, I have to admit that I don’t have a sharp mind. So I need a computer program to help me. What I want is quite simple. Given a chess layout, I want to know whether someone can win within 3 moves, assuming both players are clever enough. Take the picture above for example. There are 31 stones on it already, 16 black ones and 15 white ones. Then we know it is white turn. The white player must place a white stone at (5,8). Otherwise, the black player will win next turn. After that, however, the white player also gets a perfect situation that no matter how his opponent moves, he will win at the 3rd move.

So I want a program to do similar things for me. Given the number of stones and positions of them, the program should tell me whose turn it is, and what will happen within 3 moves.

输入:

The input contains no more than 20 cases.Each case contains n+1 lines which are formatted as follows.nx1 y1 c1x2 y2 c2……xn yn cnThe first integer n indicates the number of all stones. n<=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: xi and yi and ci. xi and yi are coordinates of the stone, and ci means the color of the stone. If ci=0 the stone is white. If ci=1 the stone is black. It is guaranteed that 0<=xi,yi<=14, and ci=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.The input is ended by n=0.

输出:

The input contains no more than 20 cases.Each case contains n+1 lines which are formatted as follows.nx1 y1 c1x2 y2 c2……xn yn cnThe first integer n indicates the number of all stones. n<=222 which means players have enough space to place stones. Then n lines follow. Each line contains three integers: xi and yi and ci. xi and yi are coordinates of the stone, and ci means the color of the stone. If ci=0 the stone is white. If ci=1 the stone is black. It is guaranteed that 0<=xi,yi<=14, and ci=0 or 1. No two stones are placed at the same position. It is also guaranteed that there is no five in a row already, in the given cases.The input is ended by n=0.