poj-2965-The Pilots Brothers' refrigerator(巧妙的位运算)

传送门

这道题和poj1753 类似,都巧妙的运用了位运算

#include <iostream> 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <string> 
#define N 1000010
#define ll long long
using namespace std;
int cs[] = {0x111f, 0x222f, 0x444f, 0x888f, 0x11f1, 0x22f2, 0x44f4, 0x88f8, 0x1f11, 0x2f22, 0x4f44, 0x8f88, 0xf111, 0xf222, 0xf444, 0xf888};
int po[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};
int aa[2][20];
int main(){
#ifndef ONLINE_JUDGE 
    freopen("1.txt", "r", stdin);
#endif
    int v1, v2, i, j, ans, tmp, t, at;
    char c;
    v1 = 0;
    for (i = 0; i < 16; i++){
        cin >> c;
        if (c == '+'){
            v1 ^= po[i];
        }
    }
    ans = 999999;
    t = 0;
    for (i = 0; i < 65536; i++){
        v2 = v1;
        tmp = 0;
        for (j = 0;j < 16; j++){
            if (i&po[j]){
                tmp++;
                v2 ^= cs[j];
                aa[t][tmp] = j;
            }
        }
        if (v2 == 0){
            if (ans >= tmp){
                ans = tmp;
                at = t;
                if (t == 0){
                    t = 1;
                }else{
                    t = 0;
                }
            }
        }
    }
    cout << ans << endl;
    for (i = 1; i <= ans; i++){
        cout << aa[at][i]/4+1 << ' ' << aa[at][i]%4+1 << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值