3404: [Usaco2009 open]cow Digit game See also number games

Source: Internet
Author: User

3404: [Usaco2009 open]cow Digit game See also number game time limit:3 Sec Memory limit:128 MB
submit:72 solved:48
[Submit] [Status] [Discuss] Description Bessie and John are playing a number game.    Betsy needs you to help her. The game was carried out in the G (1≤g≤100) field altogether. The first game begins with a positive integer Ni (l≤ni≤1,000,000). The rule of the game is this: the two sides of the operation, the current number minus a number, the number can be the current number of the largest digital, can also be the smallest non-0 digital. For example, the current number is 3014, the operator can subtract 1 into 3013, or subtract 4 into 3010. After several operations, this number becomes 0.    The loser is the one who can no longer operate. Bessie always starts the operation first. If both Betsy and John are smart enough to implement the best strategy.    Please calculate the final winner. For example, a game starts at 13. Betsy turns 13 minus 3 to 10. John can only turn 10 minus 1 to 9. Betsy then turns 9 minus 9 to 0. At last Bessie won. Input line 1th enters an integer g, followed by a line of G for one NI. Output for each game, Jobesi can win, then outputs a line "YES", otherwise the loss of a line "NO" Sample Input2
9
TenSample OutputYES
NOHINT

For the first game, Bessie simply takes the number 9 and wins.
For the second game, Bessie must take 1 (since she cannot take 0), and then
FJ can win by taking 9.

Source

Silver

Problem: Very cute game theory ... But I'm still teasing on the topic for N times-the first time I thought I could subtract 1-the maximum number of digits; the second time I thought I could subtract the smallest number of digits-the maximum number of digits, until the third time only to find that the maximum and minimum number of digits can be subtracted ... Nothing else, game theory. The classical algorithm AC

PS: But although AC, but 2800ms+, time limit is 3s, this speed compares roll coarse, so I plan to come again tomorrow to optimize the solving of the DA!!!

1/**************************************************************2Problem:34043 User:hansbug4 language:pascal5 result:accepted6Time:2804Ms7Memory:9992KB8****************************************************************/9  Ten var One I,j,k,l,m,n,t:longint; AA:Array[0..1000005,1..2] ofBoolean; -B:Array[0..1000005,1..2] ofLongint; - functionMax (x,y:longint): Longint; the          begin -               ifX>y ThenMax:=xElsemax:=y; -          End; - functionmin (x,y:longint): Longint; +          begin -               ifX<y ThenMin:=xElsemin:=y; +          End; A begin ata[0,1]:=false;a[0,2]:=true; -       fori:=1  to 1000000  Do -          begin -j:=i;k:=1; t:=9; -                whileJ>0  Do -                     begin inK:=max (k,jMoD Ten); -                          if(jMoD Ten) >0  ThenT:=min (t,jMoD Ten); toJ:=jDiv Ten; +                     End; -A[i,1]:=false; the               ifA[i-t,2] ThenA[i,1]:=true; *               ifA[i-k,2] ThenA[i,1]:=true; $A[i,2]:=true;Panax Notoginseng               if  not(A[i-t,1]) ThenA[i,2]:=false; -               if  not(A[i-k,1]) ThenA[i,2]:=false; the          End; + READLN (n); A       fori:=1  toN Do the          begin + Readln (m); -               ifA[m,1] ThenWriteln ('YES')ElseWriteln ('NO'); $          End; $ Readln; -  End.

3404: [Usaco2009 open]cow Digit game See also number games

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.