Zju 1893 A multiplication Game "Simple games"

Source: Internet
Author: User

There are many games on the Zju.

This topic is still relatively good understanding, the title probably means: Two people take a number of 2-9 in turn, from 1 to multiply, ask who's product first greater than N.

Still looking for a must-win point, but in this topic into the search for the winning interval of the problem

Take the input 1000 as an example, we can come backwards, everyone except 2 to 9 a number

1000 | 999 ...    112 | If you occupy 999 to 112, your opponent will win. The opponent must occupy the segment.

1000 | 999 ... 112 | 111 ...   56 | So the required segment is 111-?. If the 56 is occupied by the opponent, then the 56x2=112, into the inevitable section. The problem turned out to be accounted for 56.

So loop. Below 1000 | 999 ... 112 | 111 ... 56 | 55 ... 9 2 6 ... 4 | 3 ... 1

|   Winning Zone |     Fail Interval |     Win |    Defeat | Wins

In this way, the idea is already very obvious.

Source Code:

//#pragma COMMENT (linker, "/stack:16777216")//For C + + Compiler#include <stdio.h>#include<iostream>#include<fstream>#include<cstring>#include<cmath>#include<stack>#include<string>#include<map>#include<Set>#include<list>#include<queue>#include<vector>#include<algorithm>#defineMax (b) ((a) > (b))? (a): (b))#defineMin (b) ((a) < (a))? (a): (b))#defineAbs (x) (((x) > 0)? (x): (-(x)))#defineMOD 1000000007#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll; typedef unsignedLong Longull; typedef unsignedint        UINT; typedef unsignedCharUchar; template<classT> InlinevoidCheckmin (T &a,t b) {if(a>b) a=b;} Template<classT> InlinevoidCheckmax (T &a,t b) {if(a<b) a=b;}Const DoubleEPS = 1e-7      ;Const intN =1              ;Const intM =200022         ;Constll P =10000000097ll;Const intINF =0x3f3f3f3f   ;intMain () {intI, J, T, N, M, K;  while(Cin >>N) {        BOOLFlag =true;  while(N >1){            if(flag) {if(n%9==0) n/=9; Elsen = n/9+1; } Else{                if(n%2==0) n/=2; Elsen = n/2+1; } Flag=!Flag; }        if(!flag) cout<<"Stan wins."<<Endl; Elsecout<<"Ollie wins."<<Endl; }    return 0;}

Zju 1893 A multiplication Game "Simple 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.