POJ4000: National Treasures

National Treasures

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 118 Accepted: 39

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.
The great hall is represented as a two dimensional grid of R * C cells. Some cells are already occupied with the museum’s guards. All remaining cells are occupied by artifacts of different types (statues, sculptures, ... etc.) which can be replaced by new hired guards. For each artifact, few other cells in the hall are identified as critical points of the artifact depending on the artifact value, type of vault it is kept inside, and few other factors. In other words, if this artifact is going to stay in the hall then all of its critical points must have guards standing on them. A guard standing in a critical position of multiple artifacts can keep an eye on them all. A guard, however, can not stand in a cell which contains an artifact (instead, you may remove the artifact to allow the guard to stay there). Also you can not remove an artifact and leave the space free (you can only replace an artifact with a new hired guard).
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.
 2 3 
1 9 4
 1210 
8 11 5
 7 6 

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.
 2   
1    
  10 
    5
 7   

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 < 2 12) representing the type of the artifact in that cell.
The last line of the input file has two zeros.

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
512 -1 2048
2 3
512 2560 2048
512 2560 2048
0 0

Sample Output

1. 0
2. 2

题目理解:

这道题还没想完,有了一些思路先写下来。

1、题目设定在一个R*C的网格上

2、每个网格中要么有一个守卫,要么有一件宝物。对于任意一件宝物,要使它“安全”就要求它周围一些相应的网格中有守卫(而且具体要求的是哪些网格,不同类型的宝物之间都是不同的)。

3、同一个网格要么放守卫,要么放宝物,不能共存(而且题目允许的唯一的操作就是把宝物替换成守卫)。

4、现在给出网格大小,每个位置上是守卫或者宝物(宝物的类型也给出),要求将一些宝物替换成守卫,使得剩下的宝物都是安全的。求最少替换多少个守卫。

目前的进展:

1、预处理,有两种情况可以先处理掉,一是某宝物的某一个“安全网格”超出R*C的网格范围,则直接忽略掉这一个网格,二是某宝物的某一个“安全网格”上已经是一个守卫了(题目的初始已经存在一些守卫了),也可以忽略掉这个安全网格,当做这件宝物“不需要这个安全网格”。预处理完毕之后就变成了:每一件物品Vi要求Xi个安全网格,这Xi个网格都在R*C的范围内而且每个网格上都有另外一件物品。

2、建立图。有向还是无向呢?暂时建立成有向图吧,虽然觉得方向好像不影响。。。建图方法:存在Vi→Vj当且仅当Vj所在的网格是Vi所要求的一个“安全网格”

3、建完图,现在的题目就变成了:给出有向图,要求删除最少的结点使得剩下的每个结点都是独立点

解法(推测的):以结点出入度为key建立最大堆,每次从图中移除堆顶的结点,更新图,再更新堆,每点独立时完成,否则继续移除结点。

证明:没有证明,都说是推测的了,下午去图书馆看看书,等我有了把握再写程序吧。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值