ZJU 1893 A Multiplication Game 【简单博弈】

感觉ZJU上有不少博弈的题目。

这道题目还是比较好理解的,题目大概意思是:两人轮流乘一个2-9的数,从1开始乘,求谁的乘积先大于N。

还是寻找必败点必胜点,不过在这个题目里转换成了寻找必败区间必胜区间的问题

以输入1000为例,我们可以倒着来,每个人除2到9之间的一个数

1000 | 999 ... 112 |    若占住999到112,则对手必胜。 必须让对手占领此段。

1000 | 999 ... 112 | 111 ... 56 |   因此必占段是 111 -? 。如果56被对手占住,则56×2=112,入必败段。问题转化成为占56。

如此循环。如下 1000 | 999 ... 112 | 111 ... 56 | 55 ... 7 | 6 ... 4 | 3 ... 1

|   必胜区间   |   必败区间  |     胜     |     败   |    胜

到此,思路已经非常明显。

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>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0)

using namespace std;

typedef long long           ll      ;
typedef unsigned long long  ull     ;
typedef unsigned int        uint    ;
typedef unsigned char       uchar   ;

template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}

const double eps = 1e-7      ;
const int N = 1              ;
const int M = 200022         ;
const ll P = 10000000097ll   ;
const int INF = 0x3f3f3f3f   ;

int main(){
    int i, j, t, n, m, k;
    while(cin >> n){
        bool flag = true;
        while(n > 1){
            if(flag){
                if(n % 9 == 0)  n /= 9;
                else    n = n / 9 + 1;
            } else{
                if(n % 2 == 0)  n /= 2;
                else    n = n / 2 + 1;
            }
            flag =! flag;
        }
        if(!flag)
            cout << "Stan wins." << endl;
        else
            cout << "Ollie wins." << endl;

    }
    return 0;
}
时间: 2024-10-10 20:45:39

ZJU 1893 A Multiplication Game 【简单博弈】的相关文章

ACM: NBUT 1107 盒子游戏 - 简单博弈

NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format: Practice Appoint description:  System Crawler  (Aug 13, 2016 10:35:29 PM) Description 有两个相同的盒子,其中一个装了n个球,另一个装了一个球.Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作每次操作时,游戏者先看看

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

hdu 2999 sg函数(简单博弈)

Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 393    Accepted Submission(s): 132 Problem Description "Alice and Bob are playing stone game...""E

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game Problem Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

poj 2505 A multiplication game(博弈)

A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5622   Accepted: 2811 Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p =

hdu3951 Coin Game(简单博弈)

Coin Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1627    Accepted Submission(s): 936 Problem Description After hh has learned how to play Nim game, he begins to try another coin game w

[POJ1082&amp;POJ2348&amp;POJ1067&amp;POJ2505&amp;POJ1960]简单博弈题总结

鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了... 希望省选过后再回过头来好好总结一遍吧. 接下来为了看着顺眼一点...还是按照难度顺序吧   POJ1082 一道最简单的博弈题,只需要DP就可以过. 在这道题里我尽情展示了多函数多过程的代码风格.. program poj1082; const u:set of 0..20=[1,3,5,7,8,10,12]; var n,i,x,y,z:longint; f:array[1900..2002,1..12,1..31]o