All pastes #234511 Raw Edit

Untitled

public cpp v1 · immutable
·published 2006-11-02 16:38 UTC
rendered paste body
#include <cstdio>  #ifdef DBG#define D(x) x#else#define D(x) #endif long a1, b1, c1; /* * Checks if the values of a, b, c generated (till the bit position where pow_2_bit is set) for correctness* This is where the problem is, Code works correctly, albeit slowly without this function*/inline bool isCorrectGuess (long pow_2_bit, long a, long b, long c){    long mask = pow_2_bit|(pow_2_bit-1);    long new_a1, new_b1, new_c1;    new_a1 = ((b*c)^a)&mask;    new_b1 = ((a*c)^b)&mask;    new_c1 = ((a*b)^c)&mask;    //D(printf("%ld %ld %ld : %ld %ld %ld\n", new_a1&mask, new_b1&mask, new_c1&mask, a1&mask, b1&mask, c1&mask));    D(printf("%x %x %ld : %x %ld %ld\n", new_a1&mask, new_b1&mask, new_c1&mask, a1&mask, b1&mask, c1&mask));    D(printf("%d %d %d\n",(int)(new_a1 == (a1&mask)), (int)(new_b1 == b1&mask), (int)(new_c1 == c1&mask)));    if (    (new_a1 == (a1&mask)) &&            (new_b1 == (b1&mask)) &&            (new_c1 == (c1&mask))       ) {        return true;    }    return false;    /*        D(printf("%ld :%ld %ld %ld ",mask, a , b, c));        D(printf("\t%ld %ld %ld :%ld %ld %ld\n", ((b*c)^a), ((a*c)^b), ((b*a)^c), a1&mask , b1&mask, c1&mask));    }    */} /** bit : Indicates the bit we're trying to guess now. Could have done without it, but what the hell :D* pow_2_bit : 2^(bit-1), used to set the ith bit on.* a,b,c : guesses of the answer so far*/bool guess(int bit, long pow_2_bit, long a, long b, long c){    if (bit==25) {        // I don't know if this test is really necessary here, but still kept it there, just to be safe        /*if (    (a1 == ((b*c)^a)) &&                (b1 == ((a*c)^b)) &&                (c1 == ((a*b)^c))           )*/ {            printf("%ld %ld %ld\n", a, b, c);            return true;        }        return false;    }     for (int ai=0; ai<2; ai++) {        for (int bi=0; bi<2; bi++) {            for (int ci=0; ci<2; ci++) {                long new_a, new_b, new_c;                // Set the bit on only when ai/bi/ci is one                new_a = a | (ai==0?0:pow_2_bit);                new_b = b | (bi==0?0:pow_2_bit);                new_c = c | (ci==0?0:pow_2_bit);                if (isCorrectGuess(pow_2_bit, new_a, new_b, new_c) &&                          guess(bit+1, pow_2_bit<<1, new_a, new_b, new_c)) {                    return true;                }            }        }    }    return false; } int main(){    scanf ("%ld %ld %ld", &a1, &b1, &c1);    if(guess(1, 1, 0, 0, 0) == false)                printf("-1 -1 -1\n");}