F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

GO

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 547    Accepted Submission(s): 302


Problem Description
In the game of Go, two players alternate placing black and white stones on lattice points of an n ¡Á n grid, each attempting to surround as much territory (i.e., regions of unfilled lattice points) as possible. At the end of the game, the score for each player is the total area of the territory surrounded by his or her stones. Given the locations of black and white stones on a Go board at the end of a match, your task is to compute the score of each player in order to determine the winner.1
Formally, two grid lattice points with coordinates (r, c) and (r¡ä, c¡ä) are adjacent if |r - r¡ä| + |c - c¡ä| = 1. A connected region of unfilled lattice points belongs to one player¡¯s territory if all adjacent filled lattice points contain stones belonging to that player (see Figure 1). Finally, a player¡¯s score consists of the number of unfilled lattice points in his or her territory.

Note that the scoring of Go boards described here does not correspond exactly to the real game of Go: we make the simplifying assumptions that all ¡°disputes¡± have been settled so that any territories surrounded by stones of both colors are considered neutral, and that all groups on the board are considered ¡°alive.¡±

Figure 1: Diagram of a 9 ¡Á 9 Go board. Unfilled lattice points belonging to black¡¯s territory are marked with B, and unfilled lattice points belonging to white¡¯s territory are marked with W. Neutral unfilled lattice points are unmarked. In the game above, white wins by 21-3 = 18.
 

Input
The input test file will contain multiple cases, each consisting of three lines. Each test case begins with a line containing three integers, n (where 1 ¡Ü n ¡Ü 19), b, and w (where b ¡Ý 0,w ¡Ý 0 and 1 ¡Ü b + w ¡Ü n2). Here, n denotes the size of the board, b is the number of black pieces placed, and w is the number of white pieces placed. The second line of each test case contains b pairs of integers r1 c1 . . . rb cb (where 1 ¡Ü ri , ci ¡Ü n) indicating the positions of the b black stones. The third line of each test case contains w pairs of integers r`1 c`1 . . . r`w c`w (where 1 ¡Ü r`i , c`i ¡Ü n) indicating the positions of the w white stones. No two stones will be located at the same lattice point. Input is terminated by a single line containing only the number 0; do not process this line.
 

Output
For each test case, print either ¡°White wins by ¡±, ¡°Black wins by ¡±, or ¡°Draw¡±.
 

Sample Input
1 1 0 1 1 2 0 1 1 1 5 12 4 1 1 1 2 1 3 2 1 2 3 3 1 3 3 4 1 4 3 5 1 5 2 5 3 1 4 2 4 3 4 3 5 0
 

Sample Output
Draw White wins by 3 Black wins by 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 05:54:18, Gzip enabled