hdu 4462
来源:互联网 发布:新建视图 sql语句 编辑:程序博客网 时间:2024/06/06 08:32
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.
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.
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.
422 2 3 31 3422 2 3 31 40
-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<k;i++)cin>>x[i]>>y[i]; for(int i=0;i<k;i++)cin>>r[i]; int ans=11; for(int i=0;i<(1<<k);i++) { memset(vis,0,sizeof(vis)); int tmp=0; for(int j=0;j<k;j++) { vis[x[j]][y[j]]=1; if(i&(1<<j)) { tmp++; for(int ii=1;ii<=n;ii++) for(int jj=1;jj<=n;jj++) if(abs(ii-x[j])+abs(jj-y[j])<=r[j]) vis[ii][jj]=1; } } int flag=1; for(int ii=1;ii<=n;ii++) for(int jj=1;jj<=n;jj++) if(!vis[ii][jj]) flag=0; if(flag) ans=min(ans,tmp); } if(ans>k)cout<<-1<<endl; else cout<<ans<<endl; } return 0;}
阅读全文
0 0
- hdu 4462
- hdu--4462
- hdu 4462
- hdu 4462(状态压缩)
- debug hdu 4462
- HDU 4462 DFS
- HDU 4462 枚举
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- nignx 负载均衡的几种算法介绍
- 全概率公式、贝叶斯公式推导过程
- SSH更新表中某个字段值
- Unity_HTC Vive(Steam VR)_视角和输入替换
- HihoCoder
- hdu 4462
- 客官留个言吧~((o´・ェ・)っ戳这儿 -->)
- hihocoder1584 Bounce 2017icpc-北京赛区 扩展欧几里德
- 设计模式-观察者模式
- Kayaking
- LintCode 最大子数组
- 函数声明与函数表达式
- u-boot-1.1.6移植笔记(初级篇)
- HDU