zoukankan      html  css  js  c++  java
  • HDU2516-取石子游戏

    取石子游戏

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2640    Accepted Submission(s): 1503


    Problem Description
    1堆石子有n个,两人轮流取.先取者第1次能够取随意多个。但不能所有取完.以后每次取的石子数不能超过上次取子数的2倍。

    取完者胜.先取者负输出"Second win".先取者胜输出"First win".

     

    Input
    输入有多组.每组第1行是2<=n<2^31. n=0退出.
     

    Output
    先取者负输出"Second win". 先取者胜输出"First win".
    參看Sample Output.
     

    Sample Input
    2 13 10000 0
     

    Sample Output
    Second win Second win First win
     

    Source
     

    打表找规律,规律为斐波那契数列

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <queue>
    #include <set>
    using namespace std;
    int n;
    set<int>fib;
    int main(){
    
        long long a=2,b=3,c=5;
        fib.insert(2);
        fib.insert(3);
        long long end = (1<<31)-1;
        //cout<<end<<endl;
        while(c <= end){
            fib.insert(c);
            a = b;
            b = c;
            c = a+b;
        }
        while(cin >> n && n){
            if(fib.count(n)==0){
                cout<<"First win"<<endl;
            }else{
                cout<<"Second win"<<endl;
            }
        }
        return 0;
    }
    


  • 相关阅读:
    docker的安装
    Linux的常用命令
    HTTP协议,HTTPS协议,Websocket协议
    常用排序
    go的数组,切片,map
    if-else,switch,for循环
    go的函数,包以及mode的补充
    Android学习笔记——从源码看Handler的处理机制
    ElementUI
    关于IO的理解
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5099824.html
Copyright © 2011-2022 走看看