poj 2965 The Pilots Brothers(搜索)
来源:互联网 发布:淘宝新用户有什么优惠 编辑:程序博客网 时间:2024/04/29 04:30
一开始看到这个题想用BFS来做,却无从下手。在Disscuss里看到个神级code。就根据大牛的思想写下来了
分析得,要改变一个位置的状态,要进行奇数次操作,某个点进行偶数次操作是不对它的状态产生影响的。
对要改变状态的一点所在的行和列各个点都进行一次操作,可得到该点的状态改变而其余所有位置的点的状态都没有发生变化
根据上面的结论,要更改矩阵的状态,就是要对需要变更状态的某点的行列所有点都进行一次改变操作
用cnt数组存储所有更改完毕后的各个位置的操作数,将所有操作数对2取模。cnt数组中值为1的位置就是要进行变更状态操作的位置。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char data[6][6]; int cnt[6][6]; int n[20],m[20]; int sum = 0; for(int i = 1 ; i <= 4; i++) /*存入矩阵的信息*/ { for(int j = 1 ; j <=4 ; j++) { cin>>data[i][j]; } getchar(); } memset(cnt,0,sizeof(cnt)); for(int i = 1 ; i <= 4 ; i++) { for(int j = 1 ; j <= 4; j++) { if(data[i][j] == '+')/*根据矩阵的信息在cnt数组中记录每一步的操作数*/ { for(int k = 1 ; k <=4 ; k++) { cnt[k][j]+=1; cnt[i][k]+=1; } cnt[i][j]-=1; } } } for(int i = 1; i <= 4 ; i++) { for(int j = 1; j<= 4 ; j++) { cnt[i][j]%=2;/*对2取模,标记得到奇数步操作的信息*/ if(cnt[i][j]) { n[++sum] = i; m[sum] = j; } }/*奇数步操作即为要进行的操作步*/ } cout<<sum<<endl; for(int i = 1; i <= sum ; i++) { cout<<n[i]<<" "<<m[i]<<endl; } return 0;}
- poj 2965 The Pilots Brothers(搜索)
- POJ 2965 The Pilots Brothers' refrigerator 搜索
- POJ 2965 The Pilots Brothers' refrigerator(暴力搜索)
- The Pilots Brothers' refrigerator(POJ-2965)
- POJ 2965 The Pilots Brothers
- POJ 2965 The Pilots Brothers' refrigerator 搜索+枚举
- POJ 2965 The Pilots Brothers' refrigerator 记忆化搜索
- poj 2965 The Pilots Brothers' refrigerator(技巧枚举)
- POJ 2965 The Pilots Brothers' refrigerator (枚举)
- POJ 2965The Pilots Brothers' refrigerator (bfs)
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
- POJ 2965 The Pilots Brothers' refrigerator(dfs+记录路径)
- poj 2965 The Pilots Brothers' refrigerator(高斯消元)
- POJ - 2965 - The Pilots Brothers' refrigerator (高效贪心!!)
- POJ 2965 The Pilots Brothers' refrigerator(反转)
- POJ 2965 The Pilots Brothers' refrigerator (想法题)
- POJ 2965 The Pilots Brothers' refrigerator(回溯查找,dfs)
- POJ 2965 The Pilots Brothers' refrigerator(高斯消元三种方法)
- poj 2121 Inglish-Number Translator(模拟)
- zoj 1403 Safecracker(枚举)
- java 路径应对转义字符
- poj 1603 Risk(最短路)
- poj 2250 Compromise(LCS,最长公共子序列)
- poj 2965 The Pilots Brothers(搜索)
- poj 1028 Web Navigation(栈模拟)
- poj 1562 Oil Deposits(搜索,种子填充法)
- poj 2230 Watchcow(欧拉回路)
- 优化屏障(Optimization barrier)第三讲
- HDU 1116 Play on Words(欧拉回路)
- HDU 3018 Ant Trip(欧拉回路 欧拉通路,一笔画问题)
- poj 1068 Parencodings(模拟)
- poj 1250 Tanning Salon(模拟)