Please poke here.
Test instructions: Give the result of x1,x2,x3,x4,x5,x6,x7,x8 and a value m, and then give the sum of x1~x8 and M for the difference or operation, and ask M.
Ideas:
According to the bit operation characteristic, because m maximum is 32 bits, we can infer from the lowest bit sequentially, and use x>>i&1 to take the value of the right number i-1 bit.
Assuming that the first digit of the binary right is 1, the first binary result of all Xi's right start is calculated, and the cumulative TMP is compared with the most right bit of TMP and SUM, and the right of M is 1, otherwise 0;
So x1~x8 's binary most right-hand side has been calculated, and the summation of the rounding and so on.
It's an interesting question ~
Code
/**author:flint_x *created time:2015-07-20 14:19:04 *file name:whust1_I.cpp * * #include <iostream> #include <ss tream> #include <fstream> #include <vector> #include <list> #include <deque> #include < queue> #include <stack> #include <map> #include <set> #include <bitset> #include < algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype># include<cmath> #include <ctime> #include <iomanip>using namespace Std;const double eps (1e-8); typedef Long long lint; #define CLS (a) memset (A,0,sizeof (a)) #define RISE (I,A,B) for (int i = A; I <= b; i++) #define Fall (I,A,B) for (int i = A; I >= b; i--) int main () {//Freopen ("Input.txt", "R", stdin);//Freopen ("Output.txt", "w", stdout); int T;cin >> t;rise (t,1,t) {int r[10];rise (i,1,9) cin >> R[i];int sum = 0, M = 0;rise (i,0,31) {int tmp = 0;rise (j,1, 8) {tmp + = r[j]>>i&1;} if (sum + tmp)% 2! = (r[9]>>i&1)) {//X>>i&1 equivalent to 1<<i&x tmp = 8-tmp;sum = (sum + tmp)/2;m + = 1<<i;} else sum = (sum + tmp)/2;} cout << m << Endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU4149 Magic Potion (bitwise operation)