Preface: he--I heard this is a water problem, but I did not make the exam (I am too weak to say a Mao), in short, the question told me: "Bit operation each one will not interfere!!" You can't imagine that! Too weak!! ”
Test Instructions: Link
MethodGreedy + Bit arithmetic
parsing: I don't know that bit arithmetic does not interfere with each other at the time of the exam (I really "bi", this is unexpected). Well then the problem is very good, int found 31 bits, and then from the back to enumerate, calculate each answer to take 1 or 0 of the value, and then this value corresponds to this bit is 1, as long as the test answer plus this value is not more than M can, is such a very simple greedy idea.
(You've been tuning it for a long time!) Yes, that's you! )
Advertising: If someone wants the data but can not find it, please leave a message, I send you a network disk or e-mail?
Code:
#include <stdio.h>#include <algorithm>#define N 100100using namespace STD;intN, M;structnode{Chars[5] ;intNum;}; Node Door[n];intbit[ *] ;intarr[ *] ;voidInit () {intTMP =1; for(inti =1; I <= to; i++) {Bit[i] = tmp; tmp<<=1; }}intMain () {scanf("%d%d", &n, &m); for(inti =1; I <= N; i++) {scanf('%s ', DOOR[I].S);scanf("%d", &door[i].num); } init ();intAns =0;intTMP =0; for(inti = to; I >=1; i--) {intX1 =0, x2 = bit[i];//x1, 0, x2, 1; for(intj =1; J <= N; J + +) {if(door[j].s[0]==' A ') {x1 &= (door[j].num&bit[i]); X2 &= (door[j].num&bit[i]); }Else if(door[j].s[0]==' X ') {x1 ^= (door[j].num&bit[i]); X2 ^= (door[j].num&bit[i]); }Else{x1 |= (door[j].num&bit[i]); X2 |= (door[j].num&bit[i]); } }if(x1) {ans |=1<< (I-1) ;Continue; }if(!X1&&X2) {if((TMP|X2) <=m) {ans |=1<< (I-1) ; TMP |= x2; } } }printf("%d\n", ans);}
Bzoj 3668 [Noi2014] getting up difficulty syndrome greedy + bitwise arithmetic