poj 2965
枚举:位运算版。
谢谢大牛们指导!
# include <iostream>
using namespace std;
const unsigned short int A[] = {0x111f, 0x222f, 0x444f, 0x888f,
0x11f1, 0x22f2, 0x44f4, 0x88f8,
0x1f11, 0x2f22, 0x4f44, 0x8f88,
0xf111, 0xf222, 0xf444, 0xf888
};
void Bitflip(unsigned short int * x, size_t h)
{
size_t i = 0;
for (; i < 16; ++i)
if (h>>i & 0x1)
*x ^= A[i];
}
size_t Bitcount(size_t i)
{
size_t count = 0, j = 0;
for (; j < 16; ++j)
if (i>>j & 0x1) ++count;
return count;
}
int main()
{
char handle[4][4];
unsigned short int h = 0x0, x, ans = 0;
size_t i = 0, min = 17, c;
for (i = 0; i < 4; ++i) cin >> handle[i];
for (int j = 15; j >= 0; --j)
{
h <<= 1;
if (handle[j/4][j%4] == '+')
h |= 0x1;
}
for (i = 0; i <= 65535; ++i)
{
if ((c=Bitcount(i)) > min) continue;
x = h;
Bitflip(&x, i);
if (x == 0)
{
min = c;
ans = i;
}
}
cout << min << endl;
for (i = 0; i < 16; ++i)
if (ans>>i & 0x1)
cout <<i/4+1 << " " <<i%4+1 << endl;
return 0;
}
浙公网安备 33010602011771号