博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU National Treasures
阅读量:5879 次
发布时间:2019-06-19

本文共 4027 字,大约阅读时间需要 13 分钟。

National Treasures

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem 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.
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 <= 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 3512 -1 20482 3512 2560 2048512 2560 20480 0

Sample Output

1. 02. 2

Hint

The picture below shows the solution of the second test case where the two artifacts in the middle are replaced by guards.

Source

2009 ANARC
 
 
 
#include
#include
#include
#include
using namespace std;const int N=2520;vector
vt[N];int map[60][60],linker[N],vis[N];int n,m;int dir[12][2]={
{-1,-2},{-2,-1},{-2,1},{-1,2},{
1,2},{
2,1},{
2,-1},{
1,-2},{-1,0},{
0,1},{
1,0},{
0,-1}};int DFS(int u){ for(int i=0;i
>k) & 1){ int x=i+dir[k][0]; int y=j+dir[k][1]; if(x>=1 && x<=n && y>=1 && y<=m && map[x][y]!=-1){ vt[(i-1)*m+j].push_back((x-1)*m+y); vt[(x-1)*m+y].push_back((i-1)*m+j); } } } printf("%d. %d\n",++cases,Hungary()/2); } return 0;}

 

 

 

转载地址:http://dedix.baihongyu.com/

你可能感兴趣的文章
导入Mybatis_Spring项目遇到的问题
查看>>
ERP入门
查看>>
【转】@Override must override a superclass method 问题解决
查看>>
统一认证系统(三)
查看>>
CentOS6.5安装完没有网络的解决办法
查看>>
利用Nodejs & Cheerio & Request抓取Lofter美女图片
查看>>
django 部署到 apache
查看>>
crontab命令
查看>>
为什么要使用云盘?
查看>>
spring依赖注入单元测试:expected single matching bean but found 2
查看>>
C++ 用libcurl库进行http通讯网络编程(转)
查看>>
锁表 for update
查看>>
Eclipse集成javap查看字节码
查看>>
一道模拟题:改进的Joseph环
查看>>
Linux SNMP oid
查看>>
Atitit 教育与培训学校 的计划策划 v2
查看>>
Lind.DDD.LindAspects方法拦截的介绍
查看>>
【第一篇】ASP.NET MVC快速入门之数据库操作(MVC5+EF6)
查看>>
Maven依赖版本冲突的分析及解决小结
查看>>
你好,2017!
查看>>