POJ 2965 The Pilots Brothers' refrigerator (暴力枚举)
https://vjudge.net/problem/POJ-2965
与poj-1753相似,只不过这个要记录路径。poj-1753:https://www.cnblogs.com/fht-litost/p/9160723.html
题意
4*4的方格,翻转其中的一个把手,会带动同行同列的把手一起动。现要求把所有把手都翻成‘-’状态,问最少需要几步。
分析
异曲同工之妙。加个vector记录路径即可。使用状态压缩的写法输出路径也很方便。
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set> #define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
template <class T>
inline bool scan_d(T &ret){
char c;int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret = ret*+(c-'');
ret*=sgn;
return ;
}
const int N = 1e6+;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T; void testcase(){
printf("Case %d:",++T);
} const int MAXN = 5e5+ ;
const int MAXM = ;
const double eps = 1e-;
const double PI = acos(-1.0);
int n;
int g[][];
bool f;
vector<pair<int,int> > vec;
bool check(){
int t = ;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(t!=g[i][j])
return false;
return true;
} void flip(int x,int y){
g[x][y] = -g[x][y]; //需要额外再翻转
for(int i=;i<;i++){
g[x][i]=-g[x][i];
g[i][y]=-g[i][y];
}
} void dfs(int x,int y,int state){
if(state==){
f = check();
if(f){
cout<<n<<endl;
for(int i=;i<n;i++){
printf("%d %d\n",vec[i].X+,vec[i].Y+);
}
}
return;
}
if(f||y>) return;
flip(x,y);
vec.PB(MP(x,y));
if(x<) dfs(x+,y,state-);
else dfs(,y+,state-);
flip(x,y);
vec.pop_back();
if(x<) dfs(x+,y,state);
else dfs(,y+,state);
return;
}
void work(){
char s[];
f=false;
vec.clear();
for(int i=;i<;i++){
scanf("%s",s);
for(int j=;j<;j++){
if(s[j]=='+') g[i][j]=;
else g[i][j]=;
}
} for(n=;n<=;n++){
dfs(,,n);
if(f) break;
}
return;
}
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
// init();
work();
return ;
}
POJ 2965 The Pilots Brothers' refrigerator (暴力枚举)的更多相关文章
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
- POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15136 ...
- POJ - 2965 The Pilots Brothers' refrigerator(压位+bfs)
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
随机推荐
- Python中的字典详解
https://www.cnblogs.com/yjd_hycf_space/p/6880026.html
- HDU Ignatius's puzzle
链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1098] 分析: 数学归纳法 f(1) = 18 + ka; 假设f(x) = 5x^13+13x^5+k ...
- 第一周:通过汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的
姓名:吕松鸿 学号:20135229 ( *原创作品转载请注明出处*) ( 学习课程:<Linux内核分析>MOOC课程http://mooc.study.163.com/course/U ...
- “数学口袋精灵”第二个Sprint计划(第五天)
“数学口袋精灵”第二个Sprint计划----第五天进度 任务分配: 冯美欣:欢迎界面的背景音乐完善 吴舒婷:游戏界面的动作条,选择答案后的音效 林欢雯:代码算法设计 进度: 冯美欣:欢迎界面背景 ...
- Python正则表达式使用
Python正则表达式使用 参考资料: Python正则表达式| 菜鸟教程 Python正则表达式详解 - 我当道士那儿些年 - 博客园 前言 由于遇到一个提取字符串某个子串的问题,刚开始使用了暴力方 ...
- 第一章:帝国的余晖 AT&T公司
启示:自己的想法,有好的技术比什么都重要,一定要注意的是技术,不要贪小便宜,明白自己最先关心的的哪个事情. 书中内容:没有人能活两百岁,也没有公司能辉煌两百年,这就是规律,很难超越.
- Python之路3【知识点】白话Python编码和文件操作(截载)
无意发现这篇文章讲的比较好,存下来供参考: http://www.cnblogs.com/luotianshuai/p/5735051.html
- 『编程题全队』Alpha阶段事后诸葛亮分析
一.设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? Answer: (1)我们软件主要解决个人和团队的事务管理问题 (2)我们软件的定义明确和清楚 ...
- 团队项目:安卓端用百度地图api定位显示跑道
因为安卓调用api对我来说是一个完全陌生的领域,我在经过很长时间终于弄出来了,这段时间还是很有成效的,我得到了历练. 第一步:注册成为百度开发者 在百度地图开放平台创建应用.地址http://lbsy ...
- HDU 2028 Lowest Common Multiple Plus
http://acm.hdu.edu.cn/showproblem.php?pid=2028 Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个 ...