zoukankan      html  css  js  c++  java
  • URAL 1023 Buttons(巴什博弈水题)

    1023. Buttons

    Time limit: 2.0 second
    Memory limit: 64 MB

    Background

    As you surely already know, Yekaterinburg has gotten its right to hold The Summer Olympic Games of the 2032. It is planned that it will be allowed to Russia as a country-organizer to emend a program of the games a bit. So, in order to improve the command result it has been decided to replace the competition in gymnastics by the competition in the new game "Buttons".
    The rules of the game are very simple. There’s a small heap of K buttons before two players. The players in turns take buttons from the heap, moreover, at a time one can take a number of buttons from 1 up to L. The one who takes the last button is the winner.
    The rules of the Olympic Games will be a bit harder then usual. The one, who is to make a first step according to a lot, has an opportunity to fix a number K with the following restriction to it: 3 ≤K ≤ 108 (that is the exact number of buttons that has been prepared for the Olympic tournament). The player who is to make the second step fixes a number L that satisfies the following conditions2 ≤ L < K.

    Problem

    A very crucial task is given to your team: you are to write a program that should help the second player to make his choice. In other words, given a number K your program is to find a number L that guaranties a victory to the second player with a proper game of both sides.
    So, for instance, there are only three buttons in the heap, the choice L = 2 provides for the victory of the second player. Really, if the first player takes only one button at his turn, the second one wins, taking the two last buttons. On the contrary, if the first one takes two buttons, the second one wins, taking the last button.

    Input

    The standard input consists of one line, which contains an only integer number K — a number of buttons in the heap, that has fixed the first player at his turn.

    Output

    To the standard output you are to write the only number L — the maximal number of buttons that can be taken at a time which provides for the victory of the second player. If there are several those numbers L, you should write the least. If there are no such numbers, you are to write 0 to the standard output.

    Sample

    inputoutput
    3
    
    2
    

    题意:总共K个纽扣,最多取L个,问L是多少能保证一定是第二个选手赢,求最小的L。

    典型的巴什博弈啦~

    #include <iostream>
    #include <cstring>
    using namespace std;
    int  K, L;
    int main(){
        while(~scanf("%d", &K)){
            int  jilu;
            int falg = false;
            for(int i = 3; i <= K; i++){
                if(K%i == 0){
                    falg = true;
                    printf("%d
    ", i-1);
                    break;
                    
                }
            }
            if(!falg) 
            printf("0
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    剑指offer——其三
    剑指offer——其二
    剑指offer——其一
    数的读法 蓝桥杯练习题 Java
    2017小结及遇见更好的2018
    自然语言处理随笔(一)
    Shell实现Windows回收站功能
    解决win7下vc6.0打开添加文件错误 崩溃
    Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage
    String两种实例化方法的区别
  • 原文地址:https://www.cnblogs.com/titicia/p/3893128.html
Copyright © 2011-2022 走看看