Greedy
The problem of bit arithmetic ... It's basically a bitwise.
From high to low, greedy to do it ...
It's not even a digital DP.
1 /**************************************************************2 problem:36683 User:tunix4 language:c++5 result:accepted6 time:340 Ms7 memory:2052 KB8 ****************************************************************/9 Ten //Bzoj 3668 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; +typedefLong LongLL; AInlineintGetint () { at intR=1, v=0;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; - for(; isdigit (ch); Ch=getchar ()) v=v*Ten-'0'+ch; - returnr*v; - } - Const intn=1e5+Ten; in /*******************template********************/ - to intn,m,a[n],lim[ +],op[n]; + - intOptintAintBintk) { the if(k==0)returna&b; * if(k==1)returna|b; $ returna^b;Panax Notoginseng } - intMain () { the #ifndef Online_judge +Freopen ("3668.in","R", stdin); AFreopen ("3668.out","W", stdout); the #endif +N=getint (); m=getint (); -F (I,0, -) lim[i]=m>>i&1; $ Chars[5]; $F (I,1, N) { -scanf"%s", s); a[i]=getint (); - if(s[0]=='A') op[i]=0; the if(s[0]=='O') op[i]=1; - if(s[0]=='X') op[i]=2;Wuyi } the BOOLsign=1; - intans=0; WuD (I, -,0){ - intnow=1, tmp0=0, tmp1=1; AboutF (J,1, N) $Tmp0=opt (tmp0,a[j]>>i&1, Op[j]), -Tmp1=opt (tmp1,a[j]>>i&1, Op[j]); - if((TMP0>=TMP1) | | (Sign && lim[i]==0)){ - if(lim[i]==1) sign=0; Aans|=tmp0<<i; +}Elseans|=tmp1<<i; the } -printf"%d\n", ans); $ return 0; the}
View Code 3668: [Noi2014] Get up difficulty syndrome time limit:10 Sec Memory limit:512 MB
submit:904 solved:499
[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 Input3 10
and 5
OR 6
XOR 7Sample Output1
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 OROperation,Equivalent long binary mode or binary number each bit performs a logical XOR operation。If two corresponding bits are different(1, otherwise the bit is Span style= "FONT-SIZE:16PX;" >0 and For bitwise AND Operation , process two binary numbers with the same length , Two corresponding bits are 1< Span style= "FONT-SIZE:16PX;" >,, otherwise 0
For example, we will take the decimal number 5 with the decimal number 3 respectively or,XOR and and operation, can get the following result:
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 [Submit] [Status] [Discuss]
"Bzoj" "3668" "NOI2014" Get up difficulty syndrome