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

input output
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\n", i-1);
                break;

            }
        }
        if(!falg)
        printf("0\n");
    }
    return 0;
}
 

URAL 1023 Buttons(巴什博弈水题),布布扣,bubuko.com

时间: 2024-10-12 20:27:48

URAL 1023 Buttons(巴什博弈水题)的相关文章

hdu 1846 Brave Game (巴什博弈 最简单的博弈水题)

Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6434    Accepted Submission(s): 4294 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分

HDU 1846 Brave Game (博弈水题)

题意:中文...你们懂得. 析:这个就是一个水题博弈,就是一个巴什博弈定理,直接就没有变,如果你们看过我写的那个,这个题绝对水过. 附地址:http://www.cnblogs.com/dwtfukgv/p/5517818.html 看完后就懂了吧,不用说了,直接上代码就OK. 代码如下: #include <iostream> #include <string> #include <vector> #include <algorithm> #include

URAL 1039 Anniversary Party 树形DP 水题

1039. Anniversary Party Time limit: 0.5 secondMemory limit: 8 MB Background The president of the Ural State University is going to make an 80'th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor rela

URAL 1023 Buttons

这题一看就是博弈吧,,,,,,,,,没啥说的.. 一次取1~L个棋子,,最后让2赢,,,输出符合的最小的L,,,没有的话就输出0...... #include <iostream> #include<bits/stdc++.h> using namespace std; int main() { int m; scanf("%d",&m); int i; for(i=2;i<m;i++) { if(m%(i+1)==0) { printf(&quo

hdu2149Public Sale 博弈水题

#include<iostream> #include<cstdio> #include<cstring> using namespace std ; int main() { int n , m; while(~scanf("%d%d",&m , &n)) { if((n >= m)) for(int i = m;i <= n ;i++) printf("%d%c" , i , i==n?'\n':'

Brave Game HDU1846(巴什博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846 题目: Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻.今天,大家选择上机考试,就是一种勇敢(brave)的选择:这个短学期,我们讲的是博弈(game)专题:所以,大家现在玩的也是“勇敢者的游戏”,这也是我命名这个题目的原因.当然

题解报告:hdu 2188 悼念512汶川大地震遇难同胞——选拔志愿者(巴什博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 Problem Description 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每个省市都派出了大量的救援人员,这其中包括抢险救灾的武警部队,治疗和防疫的医护人员,以及进行心理疏导的心理学专家.根据要求,我校也有一个奔赴灾区救灾的名额,由于广大师生报名踊跃,学校不得不进行选拔来决定最后的人选.经过多轮的考核,形势逐渐明朗,最后的名额将在"林队"和"徐队&quo

题解报告:hdu 2149 Public Sale(巴什博弈)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=2149 Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没有拿到奖学金.现在等待他的,就是像FarmJohn一样的农田生涯.要种田得有田才行,Lele听说街上正在举行一场别开生面的拍卖会,拍卖的物品正好就是一块20亩的田地.于是,Lele带上他的全部积蓄,冲往拍卖会.后来发现,整个拍卖会只有Lele和他的死对头Yueyue.通过打听,Lele知道这场拍卖的

HDU 1846 Brave Game(巴什博弈超简单题)

题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1846 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻.今天,大家选择上机考试,就是一种勇敢(brave)的选择:这个短学期,我们讲的是博弈(game)专题:所以,大家现在玩的也是"勇敢者的游戏",这也是我命名这个题目