博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pku 1753 Flip Game(高斯消元+枚举)
阅读量:4953 次
发布时间:2019-06-12

本文共 2435 字,大约阅读时间需要 8 分钟。

Flip Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 20199   Accepted: 8752

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:
  1. Choose any one of the 16 pieces.
  2. 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

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

bwwbbbwbbwwbbwww

Sample Output

4

Source

 
编程错误点:原先只管最后的值异或而错,还有max_ans未赋初值0
 
#include
#include
using namespace std;const int mm=937;const int oo=1e9;int map[mm][mm+1],b[mm][mm+1];int ans[mm];int var,equ;int max_ans;void debug();void swap(int&a,int &b){ int tmp;tmp=a;a=b;b=tmp;}/*int abs(int x){ if(x<0)return -x;return x;}*/int gcd(int a,int b){ int t; while(b!=0) { t=b;b=a%b;a=t; }return a;}int lcm(int a,int b){ return a*b/gcd(a,b);}void dfs(int z,int dep,int k,int kans){ ans[var-dep]=z; if(dep==k) { for(int i=var-k-1;i>=0;i--) { int tmp; tmp=map[i][var]%2; for(int j=i+1;j
>s; if(s=='b')map[i*num+j][var]=0; else map[i*num+j][var]=1; //cout<

转载于:https://www.cnblogs.com/nealgavin/archive/2012/09/06/3206023.html

你可能感兴趣的文章
hdu 3367 Pseudoforest
查看>>
Apache Shiro 快速入门教程,shiro 基础教程
查看>>
网页设计
查看>>
【算法4】迪杰斯特拉双栈算法处理算术表达式
查看>>
窗口还原
查看>>
《Java程序设计》第2周学习总结
查看>>
Zabbix邮件报警设置
查看>>
常用深度学习模型
查看>>
[T-ARA][Bye Bye]
查看>>
[转]有return的情况下try catch finally的执行顺序
查看>>
ORM一对一和多对多创建的3种方式
查看>>
Azkaban使用简单笔记
查看>>
二维数组最大子数组和
查看>>
SpringBoot helloWorld
查看>>
oracle 内连接、外连接、自然连接、交叉连接练习
查看>>
LeetCode 205. 同构字符串(Isomorphic Strings)
查看>>
sql语句
查看>>
navicat连接阿里云mysql数据库服务器遇到的1130等相关问题
查看>>
Idea中更改主题后xml配置文件局部黄色背景颜色去除
查看>>
github绑定host
查看>>