博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4462 - Scaring the Birds(状态压缩+bfs)
阅读量:4207 次
发布时间:2019-05-26

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

It’s harvest season now! 
Farmer John plants a lot of corn. There are many birds living around his corn field. These birds keep stealing his corn all the time. John can't stand with that any more. He decides to put some scarecrows in the field to drive the birds away. 
John's field can be considered as an N×N grid which has N×N intersections. John plants his corn on every intersection at first. But as time goes by, some corn were destroyed by rats or birds so some vacant intersections were left. Now John wants to put scarecrows on those vacant intersections and he can put at most one scarecrow on one intersection. Because of the landform and the different height of corn, every vacant intersections has a scaring range R meaning that if John put a scarecrow on it, the scarecrow can only scare the birds inside the range of manhattan distance R from the intersection. 
The figure above shows a 7×7 field. Assuming that the scaring range of vacant intersection (4,2) is 2, then the corn on the marked intersections can be protected by a scarecrow put on intersection (4,2). 
Now John wants to figure out at least how many scarecrows he must buy to protect all his corn.
Input
There are several test cases. 
For each test case: 
The first line is an integer N ( 2 <= N <= 50 ) meaning that John's field is an N×N grid. 
The second line is an integer K ( 0<= K <= 10) meaning that there are K vacant intersections on which John can put a scarecrow. 
The third line describes the position of K vacant intersections, in the format of r 
1,c 
1,r 
2,c 
2 …. r 
K,c 
k . (r 
i,c 
i) is the position of the i-th intersection and 1 <= r 
1,c 
1,r 
2,c 
2 …. r 
K,c 
k <= N. 
The forth line gives the scaring range of all vacant intersections, in the format of R 
1,R 
2…R 
K and 0 <= R 
1,R 
2…R 
K <= 2 × N. 
The input ends with N = 0.
Output
For each test case, print the minimum number of scarecrows farmer John must buy in a line. If John has no way to protect all the corn, print -1 instead.
Sample Input
422 2 3 31 3422 2 3 31 40
Sample Output
-11

题意:有一个n*n的地图,有k个空地可以放稻草人,给出每个空地可以放的稻草人属性,属性中有个R代表这个位置可以守卫的范围,问最少需要放多少个稻草人才可以守卫这个地图。

基本的状态压缩,然后暴力枚举一遍就可以了

int n,k;int vis[51][51];int x[11],y[11],r[11];int  main(){    ios::sync_with_stdio(false);    while(cin>>n&&n)    {        cin>>k;        for(int i=0;i
>x[i]>>y[i]; for(int i=0;i
>r[i]; int ans=11; for(int i=0;i<(1<
k)cout<<-1<

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

你可能感兴趣的文章
[转]在ASP.NET 2.0中操作数据::创建一个数据访问层
查看>>
Linux命令之chmod详解
查看>>
【java小程序实战】小程序注销功能实现
查看>>
Java中子类能否继承父类的私有属性和方法
查看>>
JVM内存模型详解
查看>>
(六) Git--标签管理
查看>>
建造者模式(Builder)-设计模式(三)
查看>>
Linux-网络运维基础
查看>>
Verilog编程网站学习——门电路、组合电路、时序电路
查看>>
android——学生信息显示和添加
查看>>
Android——ImageSwitcher轮流显示动画
查看>>
Android——利用手机端的文件存储和SQLite实现一个拍照图片管理系统
查看>>
图像调优1:清晰度相关参数MTF,SFR,MTF50,MTF50P 以及TVL的概念以及换算说明
查看>>
罗永浩欲直播带货,京东说可以帮忙联系
查看>>
B站,正在变成下一个“公众号”?
查看>>
小米启动安心服务月 手机家电产品可免费清洁保养
查看>>
刘作虎:一加新品将全系支持 5G
查看>>
滴滴顺风车上线新功能,特殊时期便捷出行
查看>>
不会延期!iPhone 12S预计如期在9月发售:升级三星LTPO屏幕
查看>>
腾讯物联网操作系统TencentOS tiny线上移植大赛,王者机器人、QQ公仔、定制开发板等礼品等你来拿 !
查看>>