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:
- 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).
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 map[max_i][col])max_i=i; if(max_i!=k) {//for(int i=k;i >s; if(s=='b')map[i*num+j][var]=0; else map[i*num+j][var]=1; //cout<