Test instructions: Known as N, D1, and D2....dm,alice as a number of s1=0,bob regenerated into a number S2=S1+DK, after which they generated the number following the conditions: Si=s (i-1) +DK, or Si=s (i-1)-dk, where 1<=k< =m,s (i-2) <si<=n. The first person who cannot write a number that meets the above criteria loses.
Analysis:
Since there is no way to think of direct search and other methods, then must be to find the law. Let's push it. His condition is the best way for each person to take his own steps.
Consider three numbers: s (i-2), S (i-1), SI, assuming that the current step is to generate SI, then the condition must be satisfied is S (i-2) <si<n, and because Si is obtained by S (i-1), with the above formula into the conditional inequalities there are two cases, we separate discussion:
1.si=s (i-1) +dk
So for S (i-1) This person (set to a), he wants Si (set to B) to lose, so a in the generation of S (i-1) must be to construct a number s (i-1), so b no matter how to choose the DK can not be generated by S (i-1) legal Si.
An illegal Si is si<=s (i-2) and si>n, meaning that even the smallest dmin can not satisfy S (i-1)-dmin>s (i-2) or S (i-1) +dmin<=n, and because S (i-1) =s (i-2) + DK, brought in:
S (i-2) +dk-dmin<=s (i-2) and S (i-2) +dk+dmin>n, the DK satisfies both conditions can only be dmin, so a in the generation of S (i-1) in order to make B lose, he will choose +dmin
2.si=s (i-1)-dk
The same reasoning method, you will find that this can not be created in the time to frame others, so this is not the most conducive to their own practice.
In summary, each step will choose the most conducive to their own practice is +dmin, after the simulation, and then who first >n on who loses.
The general solution to the game problem: according to the conditions of the introduction of each person the most conducive to their own practice then: 1. Simulate the results again, 2. Directly judging the results based on the characteristics of the data, such as parity
Code:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < Cmath> #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<m;i++) {scanf ("%d", &d); Mi=min (mi,d);} int a=0,b=mi; int OK; if (mi>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\n"); else printf ("bob\n"); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4371 alicebob generation sequence until greater than n or less than or equal to S (i-2)-thinking-(pushes the optimal step by a known condition)