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 ...
随机推荐
- Kafka API: TopicMetadata
Jusfr 原创,转载请注明来自博客园 TopicMetadataRequest/TopicMetadataResponse 前文简单说过"Kafka是自描述的",是指其broke ...
- Linux 上传代码到github
1.git init 初始化 2.git clone将刚刚创建的项目克隆下来 git clone https://github.com/... 3.进入到Project,编写代码 4.项目完成后执行g ...
- Unity3D工程全资源自动检测系统
是什么 这系统到底是个啥 本系统主要用于自动监测与检测各类型资源是否正常及满足指定规范,并在第一时间把出现的问题输出到控制台与保存到文件,以供对应的负责人及时修正. 为什么 你可能经常遇到的问题 资源 ...
- 新手向:从不同的角度来详细分析Redis
最近对华为云分布式缓存产品Redis做了一些研究,于是整理了一些基本的知识拿出来与大家分享,首先跟大家分享的是,如何从不同的角度来详细使用Redis. 小编将从以下9个角度来进行详细分析,希望可以帮到 ...
- LAXCUS大数据操作系统节点挂掉后的处理
昨天回公司加班跑一个LAXCUS大数据应用,JVM直接挂了,没有留下任何异常信息,查看代码,也没有内存泄漏的问题.百思不得姐,只好去求教LAXCUS大数据操作系统的技术客服,客服查看了故障节点配置.日 ...
- 关于T/G/M/K
//扫盲贴 K, G, T,都是表数量,只是个数字,在不同的场合下表示的不同.在计算机行业中,这几个量可用来表示数据传输速度和容量,下面分别讨论,希望不了解的朋友不要被某知道上的误解了.如果有什么错误 ...
- alpha阶段的 postmortem 报告
1. 每个成员到了第二次alpha 阶段与第一次相比,取得什么进步? 成员 黄杰 学会了app环境的搭建和代码的基本理解 李炫宗 更加明白安卓代码的编写和理解 康取 对安卓界面的设计有一些了解 ...
- linux下php环境的装配以及php storm的链接
linux下php环境的装配以及php storm的链接 本次安装在deepin系统下完成 一.安装LAMP组合 Linux+Apache+Mysql+php 直接命令 sudo apt-get in ...
- 从零开始学Kotlin-操作符(3)
从零开始学Kotlin基础篇系列文章 冒号操作符 ":" 和 "::" :操作符用来定义变量.类的继承等 var name: String//定义变量 clas ...
- 从零开始学Kotlin-数据类型(2)
从零开始学Kotlin基础篇系列文章 基本数据类型 Kotlin 的基本数值类型包括 Byte.Short.Int.Long.Float.Double 等: 数据-------位宽度 Double-- ...