JZOJ5407. NOIP2017 to improve the group a training 10.21Deep

Source: Internet
Author: User
Tags min
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 ');
 }
}

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.