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

Beat drop

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 279    Accepted Submission(s): 108


Problem Description
John recently found an interesting flash game on BBS. The game is mainly about making the best of the present waterdrops and use as little waterdrops as possible to eliminate all the
waterdrops on board.Now let¡¯s briefly introduce the operations: The game board is a 6*6 square. At the beginning, there are waterdrops in some squares (in different sizes), gamers can obtain a larger waterdrop by adding little waterdrops to the square. When the number of little waterdrops in the square meets 4, the big waterdrop in the square breaks, producing 4 little waterdrops, in whatever circumstances, the broken waterdrop can only produce 4 little waterdrops, which then fly up, down left, right, four directions. When a little whatdrop meets a square that contains a waterdrop, it will be absorbed, and the one in the square will become larger, just the same as when you manually add one to the square. When multiple waterdrops arrive at £¨a square that contains a waterdrop£© simultaneously, they will be absorbed by the square. If the waterdrop touch the edge of board, it disappears. Gamers hope to use the least waterdrops to eliminate the waterdrops on board, so they can make through more levels. For further details, please visit ¡°flashempire¡±. John and other byr players are obsessed with the game, but he is just not good at it. It¡¯s mainly because after he comes up with an order to add the waterdrop, he can¡¯t imagine the layout. Now John needs your help. So you will be given a game board and how the waterdrops are distributed, and John will tell you how he is going to add the waterdrop, he hopes that you can tell him if it can make it through the level, if not, tell him what the board will be like at the end. We use a n*m square to represent the game board, and L to represent the up limit of the number of waterdrops each square can contain, the number of waterdrops in each square exceeds L, the drop breaks. And the broken water drop produces 4 little waterdrops that will fly in four directions in the same speed.
 

Input
The first line will contain an integer T indicating the number of test cases For each test case, it starts with three integers n, m, L, where n is the number of the rows, m is the number of the columns, L is the up limit of the number each square can contain. 1<= n, m <= 100£¬5 <= L<=10. Then follows a n*m matrix indicating the initial state of the game board, you are assured that every element is non-negative and no larger than L. After the matrix, there will be a number q, indicating how John is going to add the waterdrop at the qth step. John only adds waterdrop when it is stabel after putting last waterdrop. So q line follows, each contains two integers x,y indicating the location John adds waterdrop. 1<=x<=n,1<=y<=m.
 

Output
For every test case, output ¡°YES¡± or ¡°NO¡± first, indicating if John can make it the end of this stage, if it is ¡°NO¡±, it is required to output a n*m matrix indicating the final state of the game board.
 

Sample Input
3 2 2 2 2 0 0 0 1 1 1 2 2 2 2 0 0 0 1 1 2 6 6 4 4 3 2 0 0 0 3 3 0 1 2 2 1 3 2 4 2 0 3 4 1 4 4 1 3 2 2 2 3 0 3 0 3 2 1 2 6 4 3 4 3 3 2 2 2 2 6 4 4
 

Sample Output
YES NO 2 1 0 0 NO 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 4
 

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-11 20:11:50, Gzip enabled