HDU 4371 generate a series of AliceBob until n or less than or equal to S (I-2)-thinking-(push the optimal step by known conditions)

Source: Internet
Author: User
Tags cmath

HDU 4371 generate a series of AliceBob until n or less than or equal to S (I-2)-thinking-(push the optimal step by known conditions)

Meaning: n, d1, d2 .... dm, Mr. Alice into a number S1 = 0, Bob regenerate into a number S2 = S1 + dk, then their generated number follows the condition: Si = S (I-1) + dk, or Si = S (I-1)-dk, where 1 <= k <= m, S (I-2)

Analysis:

Since there is no way to directly search for such a method, it must be to find the rule. Let's take a look at his condition to get everyone's best practices for each step.

Consider three numbers: S (I-2), S (I-1), Si, assuming the current step is to generate Si, then the condition that must be met is S (I-2)

1. Si = S (I-1) + dk

So for the person S (I-1) (set to A), he wants Si (set to B) to lose, so A is generating S (I-1) is definitely to construct a number S (I-1), so that B no matter how choose dk can be generated by S (I-1) Legal Si.

Invalid Si is Si <= S (I-2) and Si> n, that is, even if the smallest dmin is selected, S (I-1)-dmin> S (I-2) or S (I-1) + dmin <= n, and because S (I-1) = S (I-2) + dk,:

S (I-2) + dk-dmin <= S (I-2) and S (I-2) + dk + dmin> n, the dk can only meet these two conditions is dmin, so when A generates S (I-1), in order to make B lose, he will select + dmin

2. Si = S (I-1)-dk

Likewise, you will find that you cannot frame others when generating your own, so this is not your best practice.

In summary, each step selects + dmin, which is the best choice for everyone, and then simulates it again. Then, whoever> n will lose.

General Solution to game problems: according to the conditions, the best practice for each person is introduced and the result is obtained through simulation. 2. The result is directly determined based on data features such as parity.

Code:

 

#include
 
  #include
  
   #include
   
    #include#include
    
     #define INF 1000000007using namespace std;int t,n,m;int d;int main(){     scanf(%d,&t); for(int cas=1;cas<=t;cas++){ scanf(%d%d,&n,&m); int mi=INF; for(int i=0;i
     
      n) ok=1;    else{    while(1){    int tmp=a;    a=b+mi;    b=a+mi;    if(a>n){    ok=0;break;    }    if(b>n){    ok=1;break;        }        }    }        printf(Case #%d: ,cas);    if(ok) printf(Alice);    else printf(Bob); }}
     
    
   
  
 


 

 

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.