POJ 1753 Flip Game DFS枚举
看题传送门:http://poj.org/problem?id=1753
DFS枚举的应用。
基本上是参考大神的。。。。
学习学习。。
- #include<cstdio>
- #include<iostream>
- using namespace std;
- int n,s,d,ans;
- bool a[5][5],flag=false;
- //判断全部一样的情况
- bool alllike()
- {
- for(int i=0;i<4;i++)
- for(int j=0;j<4;j++)
- if(a[i][j]!=a[0][0])
- return false;
- return true;
- }
- //翻转棋
- void flip(int r,int c)
- {
- if(r>0)
- a[r-1][c]=!a[r-1][c];
- if(c>0)
- a[r][c-1]=! a[r][c-1];
- if(r<3)
- a[r+1][c]=!a[r+1][c];
- if(c<3)
- a[r][c+1]=!a[r][c+1];
- a[r][c]=!a[r][c];
- }
- void dfs(int r,int c,int deep)
- {
- if(deep==ans)
- {
- flag=alllike();
- return;
- }
- if(r==4||flag)
- return;
- flip(r,c); //翻转棋
- if(c<3)
- dfs(r,c+1,deep+1);
- else
- dfs(r+1,0,deep+1);
- flip(r,c); //把棋翻回来
- if(c<3) //如果不满足则不翻转该棋
- dfs(r,c+1,deep);
- else
- dfs(r+1,0,deep);
- return;
- }
- int main()
- {
- char c;
- for(int i=0;i<4;i++)
- for(int j=0;j<4;j++)
- {
- scanf("%c",&c);
- if(j==3)
- getchar();
- // cin>>c; //直接用cin也可以
- if(c=='b')
- a[i][j]=true;
- else
- a[i][j]=false;
- }
- for(ans=0;ans<=16;ans++)
- {
- dfs(0,0,0);
- if(flag)
- break;
- }
- if(flag)
- printf("%d\n",ans);
- else
- printf("Impossible\n");
- }
POJ 1753 Flip Game DFS枚举的更多相关文章
- POJ 1753 Flip Game (DFS + 枚举)
题目:http://poj.org/problem?id=1753 这个题在開始接触的训练计划的时候做过,当时用的是DFS遍历,其机制就是把每一个棋子翻一遍.然后顺利的过了.所以也就没有深究. 省赛前 ...
- poj 1753 Flip Game (dfs)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28805 Accepted: 12461 Descr ...
- 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: 52279 Accepted: 22018 Des ...
- POJ 1753 Flip Game (枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26492 Accepted: 11422 Descr ...
- 枚举 POJ 1753 Flip Game
题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...
- poj 1753 Flip Game(bfs状态压缩 或 dfs枚举)
Description Flip game squares. One side of each piece is white and the other one is black and each p ...
- 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 ...
随机推荐
- hq-源码编译
这里编译整个项目的基本格式是 ./mk + 平台名 +项目名_客户名 +mmm +new 例如 ./mk hq6735_65c_b1k_l1 al811_doov mmm new 编译单个模块 ./m ...
- region实现大纲效果
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 具有可视化的功能的一款开源软件Gource
今天为大家介绍一个非常有趣儿的开源软件,Gource可以将代码版本控制系统里面的日志全部可视化,也就是说可以看见每个成员在系统里面提交代码的行为,Gource目前支持git,hg,svn. 650) ...
- 基于Linux平台的Openvas配置使用视频教学
常见的漏洞扫描工具有Openvas.LSAT.Nessus.X-scan.ShadowSecurityScanner和流光等,openvas是一款最全面的开源漏洞扫描工具,由于openvas安装比较困 ...
- BZOJ——T 1355: [Baltic2009]Radio Transmission
http://www.lydsy.com/JudgeOnline/problem.php?id=1355 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
- Flume的可靠性
Flume的可靠性 当节点出现故障时,日志能够被传送到其他节点上而不会丢失. Flume提供了三种级别的可靠性保障,从强到弱依次分别为:end-to- end(收到数据agent首先将event写到磁 ...
- 洛谷P1143 进制转换
题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10 ...
- select发生改变使用js提交form表单(get传值)
form表单如下: <form id="my_form" method="get" action=""> <input t ...
- int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
Android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null..空指针问题,费劲心思才找到报空指针的原因: 代码 ...
- 在window编写好的网站往linux上发布
得知ASP.NET CORE可以跨平台,我内心很躁动,毕竟自己喜欢的,之前没有学过linux导致一开始上手linux有点困难,按照https://www.microsoft.com/net/core# ...