poj2965 The Pilots Brothers' refrigerator
来源:互联网 发布:mindnode有windows版么 编辑:程序博客网 时间:2024/06/06 18:27
2017-10-5
解答
直接枚举即可
代码
#include<iostream>using namespace std;const int N = 4;char x[N+1][N+1],y[N+1][N+1];int z[N+1][N+1];int s;bool f=false;void set(int p,int q){ for (int i=1;i<=N;i++){ if (x[i][q]=='-') x[i][q]='+'; else x[i][q]='-'; if (x[p][i]=='-') x[p][i]='+'; else x[p][i]='-'; } if (x[p][q]=='+') x[p][q]='-'; else x[p][q]='+';}void init(){ int i,j; for (i=1;i<=N;i++){ for (j=1;j<=N;j++){ x[i][j]=y[i][j]; } }}void show(){ int i,j; cout<<s<<endl; for (i=1;i<=N;i++){ for (j=1;j<=N;j++){ if (z[i][j]) cout<<i<<" "<<j<<endl; } }}bool res(){ int i,j; s=0; for (i=1;i<=N;i++){ for (j=1;j<=N;j++){ if (z[i][j]){ set(i,j); s=s+1; } } } for (i=1;i<=N;i++){ for (j=1;j<=N;j++){ if (x[i][j]=='+') return false; } } return true;}void dfs(int p,int q){ if (f) return ; if (p==N+1){ if (res()){ f=true; show(); } init(); return ; } if (q==N+1){ dfs(p+1,1); return ; } z[p][q]=1; dfs(p,q+1); z[p][q]=0; dfs(p,q+1);}int main(){ int i,j; for (i=1;i<=N;i++){ for (j=1;j<=N;j++){ cin>>x[i][j]; y[i][j]=x[i][j]; } } dfs(1,1); return 0;}
阅读全文
0 0
- POJ2965 The Pilots Brothers' refrigerator
- POJ2965----The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965--The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- The Pilots Brothers' refrigerator Poj2965
- POJ2965-The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers\' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965 The Pilots Brothers' refrigerator 枚举
- poj2965——The Pilots Brothers' refrigerator
- PAT备考
- java之流程控制与数组
- 以挂起的形式创建进程
- 试题16:反转链表
- 学习笔记之装饰者模式
- poj2965 The Pilots Brothers' refrigerator
- hiho 1164 概论数学
- 遥感影像计算植被覆盖度FVC
- 代码分析基类和派生类的地址和布局的问题
- Codeforces 600E Lomsat gelral (启发式合并)
- java将数据写入csv文件,从csv文件中读取数据
- 控制台程序生成窗口
- CodeForces
- Python2 列表方法