hdu 5077 NAND(打表)2014 Asia regional 鞍山站 H题

2015-01-27 18:12:05 · 作者: · 浏览: 35

题目链接:点击打开链接

题意:就是一个按位运算的一个函数,问最少经过多少步运算可以得到给定数;

思路:不是我投机取巧想打表,是特么这题只能打表。。。打表思想用可以得到的数的集合表示状态bfs;最后有一个需要11步的需要打将近1h,除去这一个十分钟就够了。

cpp:

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
       using namespace std; int mark[300]; struct node{ int deep; vector 
       
         us; void init(){ deep=0; us.push_back(15); us.push_back(51); us.push_back(85); us.push_back(0); us.push_back(255); } bool find(int n){ for(int i=0;i
        
          Q; map
         
          ,bool> Map; //打出全部表版本的check bool check(){ int bj=1; for(int i=0;i<256;i++){ if(mark[i]<0) { bj=0; } } if(bj) for(int i=0;i<256;i++){ printf("%d , ",mark[i]); } return bj; } //留下最后一个数不打的check版本 bool check(){ int cnt=0; for(int i=0;i<256;i++){ if(mark[i]<0) { cnt++; } } if(cnt<2) for(int i=0;i<256;i++){ printf("%d , ",mark[i]); } return (cnt<2); } void bfs(){ node tpe; tpe.init(); Q.push(tpe); for(int i=0;i<5;i++) { mark[tpe.us[i]]=0; } while (!check()){ node tp=Q.front(); Q.pop(); for(int i=0;i