poj-1753-Flip Game

传送门
数据规模小,直接暴搜加位运算就行了

#include <iostream> 
#include <cstdio>
#include <cstdlib>
#define N 1000010
#define ll long long
using namespace std;
int cs[] = {0x13, 0x27, 78, 140, 305, 626, 1252, 2248, 4880, 8992, 20032, 35968, 12544, 29184, 58368, 51200};
int po[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};
int main(){
#ifndef ONLINE_JUDGE 
    freopen("1.txt", "r", stdin);
#endif
    int v1, v2, i, j, ans, tmp;
    char c;
    v1 = 0;
    for (i = 0; i < 16; i++){
        cin >> c;
        if (c == 'b'){
            v1 ^= po[i];
        }
    }
    ans = 999999;
    for (i = 0; i < 65536; i++){
        v2 = v1;
        tmp = 0;
        for (j = 0;j < 16; j++){
            if (i&po[j]){
                tmp++;
                v2 ^= cs[j];
            }
        }
        if (v2 == 0 || v2 == 65535){
            ans = min(ans, tmp);
        }
    }
    if (ans == 999999){
        cout << "Impossible";
    }else{
        cout << ans;
    }
    return 0;
}

你可能感兴趣的:(poj-1753-Flip Game)