1087: Gobang

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

Gobang is a traditional checker-type game in which the lining up of five pieces in a straight line scores victory. Up to now, it has been spread all over the world. And it is such an amusing game that at present more and more people are enjoying themselves playing it. Also, more and more players participate in the gobang contest nowadays, which result in the world championship contest of gobang coming into being. Like the game of go, the players of the game gobang are classified into several grades according to their abilities. All those happenings suggest its international tendency and express its charm. Recently, THU (Thud Habit United-Front) planned to hold a contest of gobang. So they had to draw up the rule of this contest. Compared with the game of go, the rule of the game of gobang was much simpler: * Two players play the gobang game on a board with 19 horizontal lines and 19 vertical lines intersected by each other. There are no black or white cobbles on the board before the game begins. The black player select one intersectional point on the board to put on his cobble first, then white, one by one, and so on. The player who line up of five cobbles continuously in a straight line first will score victory, no matter the straight line is horizontal, vertical or diagonal. * No one is allowed to line up of six cobbles in a straight line continuously. The one who transgress this rule will be declared to lose, but if at that time, he line up of five cobbles in another straight line, he is still the winner. But soon, they found that the black player would win most of the competitions, benefiting by going first. In fact, from beginning to end, if he could choose the best way in the match, the white player would have no chance to win. So they drew up a constraint for the black player. * A straight line of three cobbles of the same colors is called “Living three”, if there are two intersectional points without any cobbles placed on them connecting to it. When there are two “Living threes” connected to each other, we regard it as “Double Living Three”. To the black, the intersectional point to form “Double Living Three” means him a “taboo point”. If he put the black cobble on such point, he will be declared to lose. Also, if he line up of five cobbles in another straight line at the same time, he is still the winner. This constraint doesn’t affect the white player. With such a constraint drawn up, the black player has no more advantages. Now that the rules had been drawn up, THU could hold the contest soon. But unfortunately, they didn’t think their judges righteous. Although the honest recorders had written down the records of the contest, they weren’t willing to hear the announcements made by their judges. So they hoped that you could write a program for them to make the judgments automatically.

输入

The input file consists of several records. The first line of the input file contains a positive integer k, the number of the records. Then follows those records. In each record, there are a string tells the name of the black player in the first line, and a string tells the name of the white player in the second line. The next line will be an integer n (1≤n ≤361) indicating the number of the cobbles put on the board in the record. The following n lines represent the whole record. There is an integer pair x, y (1≤x, y≤19) in each line indicating the intersectional point that the player put his cobble on. The first integer x represents the horizontal line number of the point (from 1 to 19 indicates top to bottom); the second integer y represents the vertical line number of the point (from 1 to 19 indicates left to right). The first pair is the point that black cobble put on, next white, one by one, and so on.

输出

The output for each record begins with a line, which tells the record number (they are numbered sequentially starting with 1, just as record #1, record #2, …, etc.). Then you should make the judgment for the record. If no one wins, display “A draw”, otherwise, display the name of the winner. For each, you should also display the status of the board which should consists of 19 lines, each line consists of 19 characters; ‘b’ represents black cobble; ‘w’ represents white cobble; and ‘+’ represents empty point. Output should be from left to right and from top to bottom corresponds to the board. There should be a blank line after each record. Note: Dissimilar with the game of go, no cobbles will be taken away from the board. That is, no player could put cobble on the intersectional point where there exists a cobble already. But some players were so careless that although one player had won the match, but no one realized it. So the match would go on. You may ignore the cobbles put on the board after any player win the match and those cobbles shouldn’t appear in the status of the board outputted.

样例输入 复制

1
Tom
Jerry
9
10 10
1 1
10 11
1 2
10 12
1 3
10 13
1 4
10 14

样例输出 复制

record #1
Tom
wwww+++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++bbbbb+++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++

来源/分类