[BZOJ3668] [Noi2014] Getting up difficulty syndrome (greedy)

Source: Internet
Author: User

Description21st century, many people have a strange disease: Get up difficulty syndrome, its clinical manifestations are: Get up hard, get up after the bad spirit. As a young sunshine good teenager, ATM has been insisting on the struggle against getting out of trouble syndrome. By studying the relevant literature, he found the cause of the disease: in the depths of the Pacific Ocean, there is a dragon named DRD, which holds the essence of sleep, can arbitrarily prolong everyone's sleep time. It is because of the activities of DRD, get up difficulty syndrome intensified, at an alarming rate in the world spread.  To eradicate the disease, the ATM decided to go to the seabed and destroy the dragon. After all the hardships, the ATM finally came to the place where DRD, ready to start a very arduous battle. DRD has a very special skill, and his defensive warfare line is capable of using certain calculations to change the damage he receives. Specifically, DRD's defensive front is NThe fan defense door is composed. Each guard Gate includes an op op and a parameter T, where the operation must be one of the Or,xor,and, and the parameter must be a nonnegative integer. If you have not yet passed the defensive gate, attack x, the damage will be changed after the guard door x op t。 The final DRD is hurt by the opponent's initial attack. x go through all n -Fan guard DoorThe damage that is gained after the change. Due to the limited ATM level, his initial attack can only be 0 to mAn integer between (that is, his initial attack can only be 0,1,..., mOptional, but after the defensive door mRestrictions). In order to conserve energy, he hopes that by choosing the right initial attack to make his attack drd the most damage, please help him to calculate how much his attack can damage DRD.Input

The 1th line contains 2 integers, followed by n,m, to indicate that the DRD has N-Fan guard gates, and the initial attack power of the ATM is an integer between 0 and M. The next n lines, in turn, represent each of the defensive doors. Each row consists of a string op and a non-negative integer t, separated by a space, and the OP is in front, and the OP represents the action of the defensive gate, and T represents the corresponding parameter.

Output

An integer line that represents the maximum amount of damage that DRD is exposed to by an ATM attack.

Sample Input3 10
and 5
OR 6
XOR 7Sample Output1
HINT

"Sample description"
The initial attack power that the ATM can choose is 0,1,..., 10.
Assuming initial attack damage is 4, the final attack is calculated as follows
4 and 5 = 4
4 OR 6 = 6
6 XOR 7 = 1
Similarly, we can calculate that the initial attack is 1,3,5,7,9 when the final attack is 0, the initial attack is 0,2,4,6,8,10 when the final attack is 1, so an ATM attack at most causes the DRD to receive a damage value of 1.

0<=m<=10^9
0<=t<=10^9
Must be one of the Or,xor,and

"Operation Interpretation" in the subject, the player needs to convert the number into binary before the calculation.      If the two-digit binary length of the operation is different, the first 0 to the same length. The or is a bitwise OR operation, processing two binary numbers of the same length, two corresponding bits as long as one is 1, then the result value of the bit is 1, otherwise 0. XOR performs a logical XOR or operation on a bitwise XOR or operation, with each bit of the equivalent long binary mode or binary number. If the two corresponding bits are different (dissimilar), the bitthe resultsThe value is 1, otherwise the bit is 0. And for bitwise and operations, processing two binary numbers of the same length, two corresponding bits are 1, the result value of this bit is 1, otherwise 0.
For example, we use the decimal number 5 and the decimal number 3 respectively for Or,xor and and operations, the following results can be obtained:
0101 (decimal 5) 0101 (decimal 5) 0101 (decimal 5)
OR 0011 (decimal 3) XOR 0011 (decimal 3) and 0011 (decimal 3)
= 0111 (decimal 7) = 0110 (decimal 6) = 0001 (decimal 1)SourceSolution

Still missing one condition: $n \leq 10^5$

From high to low, calculate the current bit of attack $0$ results obtained by $r_0$ and take $1$ results $r_1$

There are several possibilities.

    1. $r _0=1,r_1=0$, do not think much, this one certainly choose $0$
    2. $r _0=1,r_1=1$, because if this one chooses $0$, the next few can have more choice so also chooses $0$
    3. $r _0=0,r_1=0$, with section $2$, still selected $0$
    4. $r _0=0,r_1=1$, $2$ section $3$ the so-called choice is embodied in this article, if this one chooses $1$ will not surpass $m$ to choose $1$, otherwise choose $0$, because the high $1$ is obviously cheaper than the low $1$
1#include <bits/stdc++.h>2 using namespacestd;3 intN, def[100005][2];4 5 BOOLCheckintBitintx)6 {7      for(inti =1; I <= N; ++i)8         if(def[i][0] ==1)9X &= def[i][1] &1<<bit;Ten         Else if(def[i][0] ==2) OneX |= def[i][1] &1<<bit; A         ElseX ^= def[i][1] &1<<bit; -     returnx; - } the  - intMain () - { -     intM, x, ans =0; +     BOOLr0, R1; -     Charop[5]; +scanf"%d%d", &n, &m); A      for(inti =1; I <= N; ++i) at     { -scanf"%s%d", OP, &def[i][1]); -         if(op[0] =='A') def[i][0] =1; -         Else if(op[0] =='O') def[i][0] =2; -         Elsedef[i][0] =3; -     } in      for(inti = in; ~i; --i) -     { toR0 = Check (i,0), r1 = Check (i,1<<i); +         if(R0 | |!r1)Continue; -         if(ans |1<< i) <= m) ans |=1<<i; the     } *      for(inti =1; I <= N; ++i) $         if(def[i][0] ==1) Ans &= def[i][1];Panax Notoginseng         Else if(def[i][0] ==2) Ans |= def[i][1]; -         ElseAns ^= def[i][1]; theprintf"%d\n", ans); +     return 0; A}
View Code

[BZOJ3668] [Noi2014] Getting up difficulty syndrome (greedy)

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.