poj 1753 Flip Game(暴力枚举)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 52279 | Accepted: 22018 |
Description
- Choose any one of the 16 pieces.
- Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, and to the bottom of the chosen piece (if there are any).
Consider the following position as an example:
bwbw
wwww
bbwb
bwwb
Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up. If we choose to flip the 1st piece from the 3rd row (this choice is shown at the picture), then the field will become:
bwbw
bwww
wwwb
wwwb
The goal of the game is to flip either all pieces white side up or all pieces black side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.
Input
Output
Sample Input
bwwb
bbwb
bwwb
bwww
Sample Output
4
Source
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#include<stack>
#include<string>
#include<map>
#include<numeric>
#include<set>
#include<functional>
#include<sstream>
#include<time.h>
using namespace std;
int mapp[][];
int turn1[]={,-,,,};
int turn2[]={,,,,-};
const int inf = 0x3f3f3f3f;
int ans=inf; int judge( void ) //判断棋盘是否全为0,或全为1
{
int temp=mapp[][];
for(int i = ; i<; i++)
{
for(int j = ; j<; j++)
{
if(temp != mapp[i][j])
return ;
}
}
return ;
} void turn(int x, int y)
{
for(int i=;i<;i++)
{
if(x+turn1[i]>=&&x+turn1[i]<&&y+turn2[i]>=&&y+turn2[i]<)
mapp[x+turn1[i]][y+turn2[i]]= !mapp[x+turn1[i]][y+turn2[i]];
}
} int dfs( int x, int y, int t)
{
if(judge())
{
ans=min(ans,t);
return ;
}
if(x >= || y >= )
return ;
int nx=(x+)%; //坐标,满4换成第二行
int ny=y+(x+)/; dfs(nx,ny,t); //搜索翻转
turn(x,y);
dfs(nx,ny,t+);
turn(x,y); return ;
}
int main()
{ for(int i=;i<;i++)
{
char s[];
gets(s);
for(int j=;j<;j++)
{
if(s[j]=='b') mapp[i][j]=;
else mapp[i][j]=;
}
} dfs(,,); if(ans!=inf)
printf("%d\n",ans);
else
printf("Impossible\n");
}
poj 1753 Flip Game(暴力枚举)的更多相关文章
- POJ 1753 Flip Game DFS枚举
看题传送门:http://poj.org/problem?id=1753 DFS枚举的应用. 基本上是参考大神的.... 学习学习.. #include<cstdio> #include& ...
- POJ 1753 Flip Game (DFS + 枚举)
题目:http://poj.org/problem?id=1753 这个题在開始接触的训练计划的时候做过,当时用的是DFS遍历,其机制就是把每一个棋子翻一遍.然后顺利的过了.所以也就没有深究. 省赛前 ...
- POJ 1753 Flip Game【枚举】
题目链接: http://poj.org/problem?id=1753 题意: 由白块黑块组成的4*4方格,每次换一个块的颜色,其上下左右的块也会被换成相反的颜色.问最少换多少块,使得最终方格变为全 ...
- POJ 1753 Flip Game (枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26492 Accepted: 11422 Descr ...
- POJ 1753 Flip Game 暴力 深搜
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59468 Accepted: 24750 Descr ...
- 枚举 POJ 1753 Flip Game
题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 1753 Flip Game(高斯消元+状压枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45691 Accepted: 19590 Descr ...
- POJ - 1753 Flip Game(状压枚举)
https://vjudge.net/problem/POJ-1753 题意 4*4的棋盘,翻转其中的一个棋子,会带动邻接的棋子一起动.现要求把所有棋子都翻成同一种颜色,问最少需要几步. 分析 同一个 ...
随机推荐
- python基础之变量与数据类型
变量在python中变量可以理解为在计算机内存中命名的一个存储空间,可以存储任意类型的数据.变量命名变量名可以使用英文.数字和_命名,且不能用数字开头使用赋值运算符等号“=”用来给变量赋值.变量赋值等 ...
- 图像反转(一些基本的灰度变换函数)基本原理及Python实现
1. 基本原理 获取像素值在[0, L]范围内的图像的反转图像,即为负片.适用于增强图像中白色或者灰色的区域,尤其当黑色在图片中占主地位时候 $$T(r) = L-r$$ 2. 运行结果 图源自ski ...
- Computing Jobs
docker&k8shadoopsparkhbasemesosrediskafkazookeeper SCSI.NVMe.PCIe devops
- canvas 使用图片跨域问题
项目中需要生成海报,使用了前端生成图片的插件,将背景图,详情图,以及部分的文字说明放在一块并且生成一张新的图片,大体看了一下源码是通过canvas来实现的,在本地的时候完全没有问题,提交到服务器之后就 ...
- LSTM+CRF维特比解码过程
题目:给定长度为n的序列,标签数为m(标签值表示为1,2,....,m),发射概率矩阵E(n * m),其中E[i][j]表示第i个词预测为标签j的发射概率,转移概率矩阵T(m*m),其中T[i][j ...
- (十九)c#Winform自定义控件-停靠窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 用python解析JSON
先来认识下JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使 ...
- Zabbix添加windows主机监控
zabbix监控windows主机 1.官网下载zabbix的windows-agent(选择相应版本): https://www.zabbix.com/cn/download_agents 2.将下 ...
- 【JVM从小白学成大佬】3.深入解析强引用、软引用、弱引用、幻象引用
关于强引用.软引用.弱引用.幻象引用的区别,在很多公司的面试题中经常出现,可能有些小伙伴觉得这个知识点比较冷门,但其实大家在开发中经常用到,如new一个对象的时候就是强引用的应用. 在java语言中, ...
- c语言和c++的交换函数
#include<iostream> using namespace std; namespace LiuGang{//在命名空间中写函数 void swap(int&aa,int ...