Pro.ID22464 TitleNational Treasures Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22464 AC0 Submit4 Ratio0.00% 时间&空间限制描述The great hall of the national museum has been robbed few times recently. Everyone is now worried about the security of the treasures on display. To help secure the hall, the museum contracted with a private security company to provide additional guards to stay in the great hall and keep an eye on the ancient artifacts. The museum would like to hire the minimum number of additional guards so that the great hall is secured. Surveying all the artifacts in the great hall you figured out that the critical points of any artifact (marked by a ) are always a subset of the 12 neighboring cells as shown in the grid below. Accordingly, the type of an artifact can be specified as a non-negative integer where the i-th bit is 1 only if critical point number i from the picture above is a critical point of that artifact. For example an artifact of type 595 (in binary 1001010011) can be pictured as shown in the figure below. Note that bits are numbered from right to left (the right-most bit is bit number 1.) If a critical point of an artifact lies outside the hall grid then it is considered secure. You are given the layout of the great hall and are asked to find the minimum number of additional guards to hire such that all remaining artifacts are secured. 输入Your program will be tested on one or more test cases. Each test case is specified using R+1 lines. The first line specifies two integers (1 <= R, C <= 50) which are the dimensions of the museum hall. The next R lines contain C integers separated by one or more spaces. The j-th integer of the i-th row is -1 if cell (i, j) already contains one of the museum’s guards, otherwise it contains an integer (0 <= T < 212 ) representing the type of the artifact in that cell. 输出Description The great hall of the national museum has been robbed few times recently. Everyone is now worried about the security of the treasures on display. To help secure the hall, the museum contracted with a private security company to provide additional guards to stay in the great hall and keep an eye on the ancient artifacts. The museum would like to hire the minimum number of additional guards so that the great hall is secured. Surveying all the artifacts in the great hall you figured out that the critical points of any artifact (marked by a ) are always a subset of the 12 neighboring cells as shown in the grid below. Accordingly, the type of an artifact can be specified as a non-negative integer where the i-th bit is 1 only if critical point number i from the picture above is a critical point of that artifact. For example an artifact of type 595 (in binary 1001010011) can be pictured as shown in the figure below. Note that bits are numbered from right to left (the right-most bit is bit number 1.) If a critical point of an artifact lies outside the hall grid then it is considered secure. You are given the layout of the great hall and are asked to find the minimum number of additional guards to hire such that all remaining artifacts are secured. Input Your program will be tested on one or more test cases. Each test case is specified using R+1 lines. The first line specifies two integers (1 <= R, C <= 50) which are the dimensions of the museum hall. The next R lines contain C integers separated by one or more spaces. The j-th integer of the i-th row is -1 if cell (i, j) already contains one of the museum’s guards, otherwise it contains an integer (0 <= T < 212 ) representing the type of the artifact in that cell. Output For each test case, print the following line: k. G Where k is the test case number (starting at one,) and G is the minimum number of additional guards to hire such that all remaining artifacts are secured. Sample Input 1 3 Sample Output 1. 0 Hint The picture below shows the solution of the second test case where the two artifacts in the middle are replaced by guards. Source 样例输入1 3 样例输出1. 0 提示The picture below shows the solution of the second test case where the two artifacts in the middle are replaced by guards. |