zoukankan      html  css  js  c++  java
  • URAL 1180. Stone Game (博弈 + 规律)

    1180. Stone Game

    Time limit: 1.0 second
    Memory limit: 64 MB
    Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition that this number is a nonnegative integer power of 2 (e.g. 1, 2, 4, 8 etc.). Nikifor who takes the last stone wins.You are to write a program that determines winner assuming each Nikifor does its best.

    Input

    An input contains the only positive integer number N (condition N ≤ 10250 holds).

    Output

    The first line should contain 1 in the case the first Nikifor wins and 2 in case the second one does. If the first Nikifor wins the second line should contain the minimal number of stones he should take at the first move in order to guarantee his victory.

    Sample

    input output
    8
    1
    2
    
    Problem Author: Dmitry Filimonenkov
    Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002




    解析:找规律。

    考虑例如以下样例:
    剩余石子的数量    first Nikifor
    1                              win
    2                              win
    ---- 依次选择1,2. 而且1 和 2是能够选择的。


    3                              lose
    ---- 由于你选1或2的时候,另外一个人总能一次把剩下的取完。



    4, 5                          win

    ---- 依次选择1,2,可以获胜。



    6                              lose

    7, 8                          win

    .... 从上面的规律我们能够看出当 N mod 3 == 0 我们能确认first Nikifor一定能失败;否则的话。我们能选择的最小石子的数量 = N mod 3,此时first Nikifor获胜。




    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int ans = 0;
        char c;
        while(scanf("%c", &c) && c != '
    ') ans += c - '0';     //求个位数字之和以推断数字能否被3整除,数太大。直接存不下!

    if(ans % 3 == 0) puts("2"); else printf("%d %d", 1, ans % 3); return 0; }


    .

  • 相关阅读:
    在CentOS7上安装MySQL5.7-YUM源方式
    自动重建索引
    Oracle EM12c 安装
    CentOS 7 安装oracle 11G
    oracle 11.2.0.4 dbca创建数据库时 报错ORA-12532
    CentOS 7 安装oracle 11.2.0.4 Error in invoking target 'agent nmhs' of makefile
    Oracle db file parallel write 和 log file parallel write 等待事件
    转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38
    笔记:Memory Notification: Library Cache Object loaded into SGA
    Oracle补全日志(Supplemental logging)
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5158718.html
Copyright © 2011-2022 走看看