poj The Pilots Brothers' refrigerator(DFS)
来源:互联网 发布:数学必修三编程软件 编辑:程序博客网 时间:2024/06/06 03:50
题目链接: http://poj.org/problem?id=2965
题目大意就是一个4*4的方阵只有“+”“-”两种,当变换一个位置的符号时,该符号所在的行和列所有符号都要变换,问全部变成“-”号时最少要几步,并以此输出变换的位置!
一维数组存图很巧妙,处理的时候比二维方便的多!
/4取横坐标, %4取纵坐标!
#include<iostream>using namespace std;bool arc[16];int posi[16];int posj[16];bool check(){for(int i=0;i<16;i++){if(!arc[i])return false;}return true;}bool DFS(int pos,int step){if(check()){printf("%d\n",step);for(int i=0;i<step;i++)printf("%d %d\n",posi[i],posj[i]);return true;}if(pos>=16)return false;if(DFS(pos+1,step))return true;flip(pos);posi[step]=pos/4+1;posj[step]=pos%4+1;if(DFS(pos+1,step+1))return true;flip(pos);return false;}void flip(int pos){int i=pos/4;int j=pos%4;arc[pos]=!arc[pos];for(int m=0;m<4;m++){arc[i*4+m]=!arc[i*4+m];arc[m*4+j]=!arc[m*4+j];}}int main(){char ch;for(int i=0;i<16;i++){cin>>ch;if(ch=='+')arc[i]=0;elsearc[i]=1;}DFS(0,0);return 0;}
- poj The Pilots Brothers' refrigerator(DFS)
- POJ 2965 The Pilots Brothers' refrigerator(DFS)
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
- poj 2965 The Pilots Brothers' refrigerator(dfs)
- poj 2965 The Pilots Brothers' refrigerator(dfs)
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
- poj 2965 The Pilots Brothers' refrigerator (迭代加深dfs)
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
- POJ 2965 The Pilots Brothers' refrigerator(dfs+记录路径)
- POJ 2965 The Pilots Brothers' refrigerator(dfs+枚举 || 规律)
- POJ 2965 The Pilots Brothers' refrigerator 枚举dfs
- POJ 2965-The Pilots Brothers' refrigerator(枚举&&DFS&&输出过程)
- POJ 2965 The Pilots Brothers' refrigerator(回溯查找,dfs)
- POJ 2965 The Pilots Brothers' refrigerator(dfs or 规律)
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- The Pilots Brothers' refrigerator(POJ 2965)(dfs枚举+状态压缩)
- POJ 2965 The Pilots Brothers' refrigerator(枚举+DFS)
- POJ 2965 The Pilots Brothers' refrigerator (DFS + 枚举)
- poj Flip Game
- LED控制实验
- Android Studio 如果修改LogCat的颜色,默认全是黑色看着挺不舒服的
- Mybatis 分页查询
- Python的Distutils模块
- poj The Pilots Brothers' refrigerator(DFS)
- 基于Struts2的文件上传
- 源码编译CEF3
- C#随机产生10位大写字母的字符串
- getDateStr,Date类型,转化,日期
- java 改变窗体状态(最大化、最小化、正常)
- 找不到 System.Windows.Ria的解决办法
- 文件被多个中间文件输出目录相同的工程包含
- 基于opencv的手势识别