Filp Game
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 25573 | Accepted: 11052 |
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<stdio.h>
#include<string.h>
#include<stdlib.h>
int map[][];
int step;
int flag;
int check()
{
int i,j;
for(i=;i<=;i++)
for(j=;j<=;j++)
if(map[i][j]!=map[][])
return ;
return ;
}
void fanzhuan(int x,int y)
{
map[x][y+]=!map[x][y+];
map[x][y-]=!map[x][y-];
map[x+][y]=!map[x+][y];
map[x-][y]=!map[x-][y];
map[x][y]=!map[x][y];
}
void dfs(int x,int y,int sum)
{
if(sum==step)
{
flag=check();
return ;
}
if(x<=)
{
fanzhuan(x,y);
if(y<=)//必须是3,因为下面的y+1让y变成了4,达到最大值
dfs(x,y+,sum+);
else dfs(x+,,sum+);
if(flag==)return ;
else
{
fanzhuan(x,y);
if(y<=)
dfs(x,y+,sum);
else
dfs(x+,,sum);
}
}
else return ;
}
int main()
{
memset(map,,sizeof(map));
int i;
char str[][];
for(i=;i<=;i++)
scanf("%s",str[i]);
int t;
for(i=;i<=;i++)
{
for(t=;t<=;t++)
if(str[i][t]=='b')
map[i+][t+]=;
}
for(step=;step<=;step++)
{
dfs(,,);
if(flag)
{
printf("%d\n",step);
break;
}
}
if(flag==)printf("Impossible\n");
return ;
}
Filp Game的更多相关文章
- php扩展1:filp/whoops(用于调试,方便定位错误点)
一.composer下载filp/whoops: 1.在composer.json中添加:"filp/whoops": "*",如下所示: 2.执行compos ...
- matlab学习笔记11_3高维数组操作 filp, shiftdim, size, permute, ipermute
一起来学matlab-matlab学习笔记11 11_3 高维数组处理和运算 filp, shiftdim, size, permute, ipermute 觉得有用的话,欢迎一起讨论相互学习~Fol ...
- Metro Win8风格的按钮(Filp翻转)
原地址->http://www.cnblogs.com/yk250/p/5661093.html 介绍:简约而不简单....颜色可随意调制,最好用Blend工具. 效果图如下:话说这个图会不会太 ...
- java Channel filp compact
import java.nio.ByteBuffer; //Listing 7-1. Copying Bytes from an Input Channel to an Output Channel ...
- Bringing Whoops Back to Laravel 5
You might be missing the "prettier" Whoops error handler from Laravel 4. If so, here's how ...
- Linux设备管理(二)_从cdev_add说起
我在Linux字符设备驱动框架一文中已经简单的介绍了字符设备驱动的基本的编程框架,这里我们来探讨一下Linux内核(以4.8.5内核为例)是怎么管理字符设备的,即当我们获得了设备号,分配了cdev结构 ...
- Linux字符设备驱动框架
字符设备是Linux三大设备之一(另外两种是块设备,网络设备),字符设备就是字节流形式通讯的I/O设备,绝大部分设备都是字符设备,常见的字符设备包括鼠标.键盘.显示器.串口等等,当我们执行ls -l ...
- blocking and unblocking mechanism for linux drivern code
概念: 1> 阻塞操作 是指在执行设备操作时,若不能获得资源,则挂起进程直到满足操作条件后再进行操作.被挂起的进程进入休眠,被从调度器移走,直到条件满足: 2> 非阻塞操作 在 ...
- Linux基礎知識 —— open&close
下面說一下在用戶空間調用open/close/dup跟驅動中的open和release的對應. 下面是測試驅動: #include <linux/module.h> #include &l ...
随机推荐
- PHP中九大缓存技术总结
PHP缓存包括PHP编译缓存和PHP数据缓存两种.PHP是一种解释型语言,属于边编译边运行的那种.这种运行模式的优点是程序修改很方便,但是运行效率却很低下.PHP编译缓存针对这种情况做改进处理,使得P ...
- dp题目列表
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- java复制文件
package com.test.tes; import java.io.File; import java.io.FileInputStream; import java.io.FileOutput ...
- [ruby on rails] 跟我学之(10)数据输入验证
这里简单加上几个验证,非空,最小长度,唯一 修改模型 修改app/models/post.rb文件,如下: class Post < ActiveRecord::Base #attr_acces ...
- redis配置文件redis.conf参数说明
redis配置文件redis.conf参数说明 (2013-01-09 21:20:40)转载▼ 标签: redis配置 redis.conf 配置说明 杂谈 分类: nosql # By defau ...
- 基础02 Java 跨平台原理
1993 , JAVA初衷: 机顶盒 1994 年互联网刚刚兴起,.(高司令\ 高斯林),改造成了面向互联网的计算机语言.java重要特性之 ------- 跨平台(一次编译,到处运行).平台:操作系 ...
- Js注释
注释 介绍 作用 合作分享:方便他人阅读,便于分享 沉淀总结:容易忘记代码,自己总结沉淀 形式 1.// 双斜杠 2./**/斜杠星号 常用标签 标签 描述 @module 标明当前文件模块,在这个文 ...
- percona-toolkit 之 【pt-heartbeat】说明
背景: MySQL的架构中,Master-Slave是目前最受欢迎的,用的也最多,但是对于主从的延迟一般都是按照他自己的状态[Seconds_Behind_Master]来查看的,最近看了[不要用该值 ...
- ABAP 权限程序
检查用户销售区域与分销渠道的权限 AUTHORITY-CHECK OBJECT 'V_VBAK_VKO' ID 'VKORG' FIELD wa_all-vkorg ID 'V ...
- android ExpandableListView详解
ExpandableListView是android中可以实现下拉list的一个控件,是一个垂直滚动的心事两个级别列表项手风琴试图,列表项是来自ExpandableListViewaAdapter,组 ...