Description
The failed burning Legion wanted to escape to the abyss, and Khadgar wanted to chase them.
However, there is only one portal to the abyss, and the Burning Legion and the Khadgar each have some mana crystals, each of which can make the following choices: Khadgar
• Use a mana crystal to increase the mana level of the portal by one.
• Do not use the Force crystal, let the other side increase equal to the depth of the portal Mana level, and then clear the Mana value of the portal. In particular, this can not be done if the number of mana crystals is nonzero and the portal mana level is zero.
Both sides will adopt the optimal strategy to make their final depth and the depth of the opponent the greatest difference (initial depth of 0).
Now multiple times given the number of mana crystals of the beginning of a, B, the final depth difference between the Khadgar and the Burning Legion is obtained. Input
T
A1 B1
A2 B2
...
At BT Output
Outputs a T-line T-integer representing the depth difference between the Khadgar and the Burning Legion. Sample Input
2
0 1
4 1 Sample Output
-1
1 Data Constraint
For 30% of the data, there are t= 1; 0 <= A, B <= 10
For another 20% of the data, there is T <= 10^5; 0 <= A, B <= 10^2
For 100% of data, there is T <= 10^5; 0 <= A, B <= 10^5
For each mana crystal you own, you can add a bit more depth to yourself.
When the other's Mana crystal is 0, all the mana crystals in their hands can add depth to themselves.
All, for every a>b situation, can be transformed into a=b,
Then the more they come out into their depths.
No matter when, the initiator is unfavorable, the back will always choose not to use the Force crystal, you can know when the a=b, the depth difference is 2. Code
#include <queue> #include <cstdio> #include <iostream> #include <algorithm> #include < cstring> #include <string.h> #include <cmath> #include <math.h> #define LL Long long #define N 5003 #
Define DB double #define P putchar #define G getchar #define MO 998244353 using namespace std;
Char ch;
void read (int &n) {n=0;
Ch=g ();
while ((ch< ' 0 ' | | ch> ' 9 ') && ch!= '-') ch=g ();
ll W=1;
if (ch== '-') w=-1,ch=g ();
while (' 0 ' <=ch && ch<= ' 9 ') n= (n<<3) + (n<<1) +ch-' 0 ', ch=g ();
N*=w; } int max (int a,int b) {return a>b?a:b;} int min (int a,int b) {return a<b?a:b;} ll ABS (LL x) {return x<0?-x:x;} ll SQR (ll x) {return x*x;} void Write (ll x) {if (x>9) write (X/10);
P (x%10+ ' 0 ');}
int ans,a,b,t;
int dg (int a,int b,int door,int s,bool bz) {if (a==0 && b==0 && door==0) return s;
if (BZ)//max-->a {int mx=-2147483647; if (door!=0 | | a==0) Mx=max (MX,DG (a,b,0,s-door,0));
if (a>0) Mx=max (MX,DG (a-1,b,door+1,s,0));
return MX;
} else//min-->b {int mi=2147483647;
if (door!=0 | | b==0) mi=min (MI,DG (a,b,0,s+door,1));
if (b>0) mi=min (MI,DG (a,b-1,door+1,s,1));
return mi;
}} int main () {freopen ("deep.in", "R", stdin);
Freopen ("Deep.out", "w", stdout);
Read (T);
while (t--) {read (a); Read (b); ans=a==0 | |
B==0?a-b:a-b-2;
if (ans<0) P ('-'), write (-ans); else write (ans);
P (' \ n ');
}
}