UVA-12293 (combo game)

Source: Internet
Author: User

Test instructions

There are two identical boxes, a box with n balls, another box with 1 balls, each emptying the ball less box, and then take the empty box from the other box so that after the operation of the two boxes at least one ball, judge whether it is the winner or the latter;

Ideas:

A SG function that takes at least one and no more than half the same at a time;

AC Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath>//#include <bits/stdc++.h> #include <stack>using namespace std; #define for (i,j,n) for (int i=j;i <=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long LONG ll;template<class t> void Read (T&num)    {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=2e6+10;const int Maxn=500+10;const double eps=    1e-8;int get_sg (int x) {if (x%2==0) return X/2; Return Get_sg (X/2);}        int main () {int n;          while (1) {  Read (n);            if (n==0) break;            if (GET_SG (n)) printf ("alice\n");        else printf ("bob\n");  } return 0;}

  

UVA-12293 (combo game)

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.