Bzoj 3668: [Noi2014] Get up difficulty syndrome (greedy)

Source: Internet
Author: User

Before thought Xor,or,and satisfies the Union law ... And then we can't even get through the sample.

In the morning in P.E. class suddenly think out ... Direct processing of each bit is the final result of 1,0, and then from high to low greed can be ...

Go to dinner.

-----------------------------------------------------------------------

#include <bits/stdc++.h>using namespace std;#define B (i) (1 << (i))const int MAXN = 100009;const int L =;Char OPT[MAXN];int X[MAXN], N, M, ans[50][2];void init () {scanf ("%d%d", &n, &m);Char s[10];for (int i = 0; i < N; i++) {scanf ("%s", s);scanf ("%d", x + i);Opt[i] = s[0];}}void Work () {for (int i = 0; i < L; i++)For (int j = 0; J < 2; J + +) {int t = j;for (int k = 0; k < N; k++) switch (Opt[k]) {Case ' A ': t &= (b (i) | x[k]) = = X[k]; break;Case ' O ': t |= (b (i) | x[k]) = = X[k]; break;Case ' X ': t ^= (b (i) | x[k]) = = X[k]; break;Default:break;    }ans[i][j] = t;}int ANS = 0, c = 0;for (int i = L; i--;)if (ans[i][0]) ans |= B (i);else if (ans[i][1] && (b (i) | c) <= M)C |= B (i), ANS |= B (i);printf ("%d\n", ANS);} int main () {init ();Work ();return 0;}

-----------------------------------------------------------------------

3668: [Noi2014] Get up difficulty syndrome Time Limit:Ten Sec Memory Limit:Mb
Submit:1054 Solved:596
[Submit] [Status] [Discuss] Description

21st 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 made up of N -Fan defensive doors. Each guard gate consists of 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 the attack has not yet passed through the guard Gate, the attack damage will change to x op t. The final DRD is hurt by the opponent's initial attack x in turn through all the n -door defensive doors . due to the limited ATM level, his initial attack can only be an integer between 0 and m (i.e. his initial attack can only be selected in 0,1,..., m , but the attack after the defensive gate is not subject to m Restrictions). 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 Input 3 10
and 5
OR 6
XOR 7Sample Output 1
HINT

"Sample Description 1"

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 to binary before the calculation . If the two-digit binary length of the operation is different, the first 0 to the same length.


ORfor bitwise OR Operation,handle two binary numbers with the same length,two corresponding bits as long as there is one for1,The result value of the bit is1,Otherwise, the0. XORfor bitwise XOR orarithmetic,equivalent Long binary mode or binary number each bit performs a logical XOR operation. if two corresponding bits are different(Phasedifferent),The result value of the bit is1,otherwise the bit is0. andfor bitwise AND Operation,handle two binary numbers with the same length,two corresponding bits are1,The result value of this bit is1,Otherwise, the0.


For example, we will have a decimal number 5 with decimal number 3 carried out separately OR , XOR with the and operation, 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)

Source

Bzoj 3668: [Noi2014] Get 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.