POj 1753--Flip Game(位运算+BFS)
|
Flip Game
Description
Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip 3 to 5 pieces,
thus changing the color of their upper side from black to white and vice versa. The pieces to be flipped are chosen every round according to the following rules:
Input
The input consists of 4 lines with 4 characters "w" or "b" each that denote game field position.
Output
Write to the output file a single integer number - the minimum number of rounds needed to achieve the goal of the game from the given position. If the goal is initially achieved, then write 0. If it's impossible to achieve the goal, then write the word "Impossible"
(without quotes). Sample Input bwwb Sample Output 4 Source
我不得不说位运算是一个强大的东西,之前从来没怎么用过。没想到这么一道本来没有头绪的题,位运算一优化成了一道裸一维的BFS,说这个题目。大意是一个翻牌游戏。牌有黑白两面,当翻到全部的牌都是黑或都是白时,满足状态,输出最小操作步数。每一个位置的牌的都能够翻,但如过翻了当前这张牌。它的相邻的位置的牌都要翻过来。对于全部的状态。一共同拥有2^16种(4*4的图)
而对于翻牌操作,如果当前状态为s 想要翻第i个位置的牌。仅仅要s^=1<<i;就可以。
#include <iostream>
#include <cstdio> |
POj 1753--Flip Game(位运算+BFS)的更多相关文章
- POJ 1753 Flip Game(状态压缩+BFS)
题目网址:http://poj.org/problem?id=1753 题目: Flip Game Description Flip game is played on a rectangular 4 ...
- poj 1753 Flip Game 枚举(bfs+状态压缩)
题目:http://poj.org/problem?id=1753 因为粗心错了好多次……,尤其是把1<<15当成了65535: 参考博客:http://www.cnblogs.com/k ...
- 枚举 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(二进制枚举)
题目地址链接:http://poj.org/problem?id=1753 题目大意: 有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白->黑)时, ...
- POJ 1753 Flip Game(高斯消元+状压枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45691 Accepted: 19590 Descr ...
- POJ 2531 Network Saboteur 位运算子集枚举
题目: http://poj.org/problem?id=2531 这个题虽然是个最大割问题,但是分到dfs里了,因为节点数较少.. 我试着位运算枚举了一下,开始超时了,剪了下枝,1079MS过了. ...
- POJ - 1753 Flip Game(状压枚举)
https://vjudge.net/problem/POJ-1753 题意 4*4的棋盘,翻转其中的一个棋子,会带动邻接的棋子一起动.现要求把所有棋子都翻成同一种颜色,问最少需要几步. 分析 同一个 ...
- POJ 2436 二进制枚举+位运算
题意:给出n头牛的得病的种类情况,一共有m种病,要求找出最多有K种病的牛的数目: 思路:二进制枚举(得病处为1,否则为0,比如得了2 1两种病,代号就是011(十进制就是3)),首先枚举出1的个数等于 ...
随机推荐
- 小程序四:视图之WXSS
WXSS(WeiXin Style Sheets)是MINA设计的一套样式语言,用于描述WXML的组件样式. WXSS用来决定WXML的组件应该怎么显示. 为了适应广大的前端开发者,我们的WXSS具有 ...
- MySQL-事务隔离级别设置
加锁研究:http://www.cnblogs.com/JohnABC/p/4377529.html 先了解下 第一类丢失更新.脏读.不可重复读.幻读.第二类丢失更新 第一类丢失更新 撤销一个事务时, ...
- redis安装配置文件配置
环境: 虚拟机redhat5.5安装redis4.0.2 虚拟机IP:192.168.60.130 reids端口:6379 安装步骤不详述了(可参考: 亲密接触Redis-第一天), 大致步骤如下: ...
- java学习之第五章编程题示例(初学篇)
/* Animal.java */ package animal; public abstract class Animal { public abstract void cry(); public ...
- Android四款系统架构工具
开发者若想开发出一款高质量的应用,一款功能强大的开发工具想必是不可或缺的.开发工具简化了应用的开发流程,也能使开发者在应用开发本身投入更多的精力.本文就为大家带来4款实用的Android应用架构工具. ...
- iOS NSString去除其他字符(空格回车符)
很多时候大家都需要对字符串进行处理.现在就对字符串删掉特殊字符的处理进行总结一下. 1.stringByTrimmingCharactersInSet 这个方法只能对字符串前后两个部分的特殊字符进行 ...
- linux 硬件设备文件名
- RHCE7 管理II-5管理进程的优先级
进程的优先级值称为进程的nice值,共有40种不同的取值(用数字-20到19表示) nice值越大,表示进程的优先级越低. 进程的nice值,只允许root用户来设置负的nice:其他用户只允许设置正 ...
- Linux时间子系统(十二) periodic tick
一.tick device概念介绍 1.数据结构 在内核中,使用struct tick_device来抽象系统中的tick设备,如下: struct tick_device { struct ...
- Unity3d的lodgroup调节
才发现,假设不惬意LodGroup的百分比调节,能够在通过质量->中的Lod Bias值进行调节. 值为0-1之间 ,表示靠近精细与粗糙Lod的比率. 这样能解决用百分比调节不给力的问题.
Consider the following position as an example: