poj2965 The Pilots Brothers' refrigerator 枚举 暴力 递归
来源:互联网 发布:女朋友 文艺青年 知乎 编辑:程序博客网 时间:2024/06/08 14:30
这道题和poj1753基本上是一毛一样的,只不过是当你变一个把手时,要将这个把手的所在行和所在列的把手都变了。
然后输出多加了操作,那也好办,我们将成功的组合数保存下来,最后输出的时候转换一下行和列就ok了。。。
代码:
#include<stdio.h>#include<iostream>using namespace std;int st[17];int lab[17]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};int nst[17];int fan(int *b,int num){ int nnst[17]; for(int i=1; i<=16; i++)nnst[i]=st[i]; for(int i=1; i<=num; i++) { nnst[b[i]]=!nnst[b[i]]; int c=b[i]%4; if(!c)c=4; int r=(b[i]-1)/4; for(c; c<=16; c+=4) { nnst[c]=!nnst[c]; } r=r*4+1; for(int k=4; k>=1; r++,k--) { nnst[r]=!nnst[r]; } } int opp=0; for(int i=1; i<=16; i++) { if(nnst[i]==0)opp++; } if(opp==16) { return 1; } return 0;}int solve(int *a,int s,int e,int *b,int k,int i){ if(k==i+1) { if(fan(b,i)) { return 1; } return 0; } for(int x=s; x<=e; x++) { b[k]=a[x]; if(solve(a,x+1,e,b,k+1,i)) { return 1; } } return 0;}int main(){ char c; while(cin>>c) { int i=1; int op=0; int cl=0; if(c=='-') { op++; st[i]=0; } else { cl++; st[i]=1; } for(i=2; i<=16; i++) { cin>>c; if(c=='-') { op++; st[i]=0; } else { cl++; st[i]=1; } } if(op==16) { printf("0\n"); } else { int ans=0; for(i=1; i<=16; i++) { if(solve(lab,1,16,nst,1,i)) { ans=i; break; } } printf("%d\n",ans); for(int i=1; i<=ans; i++) { int r=(nst[i]-1)/4+1; int c=nst[i]%4; if(!c)c=4; printf("%d %d\n",r,c); } } }}
阅读全文
0 0
- poj2965 The Pilots Brothers' refrigerator 枚举 暴力 递归
- 暴力枚举-POJ2965 The Pilots Brothers' refrigerator
- POJ2965 The Pilots Brothers' refrigerator 枚举
- POJ2965,The Pilots Brothers' refrigerator,枚举,DFS
- POJ2965 The Pilots Brothers' refrigerator(枚举)
- 枚举 poj2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator(枚举,压缩)
- poj2965 The Pilots Brothers' refrigerator dfs+枚举
- 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
- The Pilots Brothers' refrigerator Poj2965
- POJ2965-The Pilots Brothers' refrigerator
- 生成函数
- python 迭代器和解析
- C++用控制器函数实现格式化I/O范例
- 提高客户管理系统应用价值的五种方法
- 最小点权覆盖集&最大点权独立集
- poj2965 The Pilots Brothers' refrigerator 枚举 暴力 递归
- KNN分类算法java实现
- Equivalent Strings
- 写一个ButterKnife
- 使用控制台执行MySQL命令时,出现1366错误的原因与解决方案
- sax、dom和dom4j、jdom区别
- IOS逆向笔记之重新签名(非越狱)
- Perl中的alarm、eval、die的联合使用
- HDU