Bzoj 3668 [Noi2014] getting up difficulty syndrome greedy + bitwise arithmetic

Source: Internet
Author: User

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&AMP;&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.