某鄰居的WIFI密碼

看到這麼小氣的鄰居,屌絲不能忍了!!! 暴力DFS破解之~

#include <cstdio>
#include <vector>
using namespace std;
bool mark[9];
vector <int>ans;
int cas=0;
void check()
{
        int tp3=ans[0]-ans[1];
        int tp6=ans[3]/ans[4];
        int tp9=ans[6]+ans[7];
        if(tp3*tp6==tp9&&tp3==ans[2]&&tp6==ans[5]&&tp9==ans[8])
        {
                printf("Case #%d:\n",++cas);
                for(int i=0;i<9;i++)
                {
                        printf("%d ",ans[i]);
                        if(i%3==2)
                        {
                                puts("");
                        }
                }
        }
}
void dfs(int deep)
{
        if(deep==9)
        {
                check();
        }
        for(int i=9;i>0;i--)
        {
                if(mark[i]==0)
                {
                        mark[i]=1;
                        ans.push_back(i);
                        dfs(deep+1);
                        ans.pop_back();
                        mark[i]=0;
                }
        }
}
int main()
{
        dfs(0);
        return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章