hdu 4462 Scaring the Birds # 暴力枚举(状压)
来源:互联网 发布:双色球红球246算法 编辑:程序博客网 时间:2024/05/22 03:52
其实是枚举的水题,也是当年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
- hdu 4462 Scaring the Birds # 暴力枚举(状压)
- HDU 4462 Scaring the Birds (暴力枚举DFS)
- hdu 4462 Scaring the Birds (暴力)
- hdu 4462 Scaring the Birds(暴力,细读)
- HDU 4462 Scaring the Birds (枚举+暴搜)
- HDU 4462 Scaring the Birds(状态压缩枚举)
- Hdu 4462 Scaring the Birds(枚举子集)
- HDU 4462 Scaring the Birds(dfs)
- hdu 4462 Scaring the Birds【Dfs+暴力判断】
- HDU 4462(Scaring the Birds)
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- hdu 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU 4462Scaring the Birds(枚举所有状态)
- hdu 4462 Scaring the Birds 状压枚举 (或dfs)
- HDU Scaring the Birds
- Leetcode 169
- OkHttp面试相关知识
- matplotlib散点图,圆
- SSH缓存开启和配置
- 2017-9-14 笔试真题
- hdu 4462 Scaring the Birds # 暴力枚举(状压)
- UVA
- 设计模式-----工厂模式
- Mac下配置环境变量使用adb命令
- 测试人员掌握代码的重要性
- 抓取搜狗微信百度新闻网易新闻
- EF Core DBFirst
- request.getParameter()和request.getInputStream()与request.getReader()
- POJ2758 斐波那契数列 0ms