hdu 4462 Scaring the Birds # 暴力枚举(状压)


其实是枚举的水题,也是当年regional的签到题,然而我卡了一个小时,啊啊啊啊啊啊啊

暴力枚举,可以用状压表示状态就是2^10,其他也没什么了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

struct node{
    int x , y , r ;
    //node(int x , int y , int r):x(x) ,y(y),r(r){}
    bool operator < ( const node & k ) const {
        return r < k.r ;
    }
};
node save[20] , temp[20];
bool pic[200][200] ;
int n , res;
int get_bit(int x){
    int ans = 0 ;
    while(x){
        if(x & 1) ans ++ ;
        x >>= 1 ;
    }
    return ans ;
}
void work(int x){
    int bit = get_bit(x) ;
    if(bit >= res) return ;
    int pos = 0 , tpos = 0 ;
    while(x){
        if(x & 1) temp[pos++] = save[tpos] ;
        x >>= 1 , tpos ++ ;
    }
    int k ;
    for(int i = 1 ; i <= n ; i ++ ){
        for(int j = 1 ; j <= n ; j ++ ){
            if( pic[i][j] ) continue ;
            for(k = 0 ; k < pos ; k ++ ){
                //cout << temp[i].x << " " << temp[i].y << "     " ;
                if( fabs(i - temp[k].x )+ fabs(j - temp[k].y)  <= temp[k].r )  break ;
            }
            //cout << k << endl ;
            if( k >= pos ) return ;
        }
    }
    //cout << 25423;
    res = bit ;
}
int main()
{
    int point , a , b , r;
    while( ~ scanf("%d" , &n) && n ){
        scanf("%d" , &point) ;memset(pic , 0 , sizeof(pic)) ;
        for(int i = 0 ; i < point ; i ++){
            scanf("%d %d" , &a , &b);
            save[i].x = a , save[i].y = b ;
            pic[a][b] = true ;
        }
        for(int i = 0 ; i < point ; i ++ ){
            scanf("%d" , &r) ;
            save[i].r = r ;
        }
        res = 100 ;

        work( (1<<point)- 1 ) ;
        if(res == 100 ){ printf("-1\n") ; continue ; }

        for(int i = 1 ; i < (1<<(point)) ; i = i<<1 )work(i) ;
        for(int i = 0 ; i < (1<<(point)) ; i ++ )    work(i) ;
        printf("%d\n" , res ) ;
    }
    return 0 ;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值