zoukankan      html  css  js  c++  java
  • POJ 2505

    博弈题。

    初始时p=1,可以从2-9中任选一个数与之相乘,给定一个数n,当最先令p>=n的为获胜。

    可以知道,当ceil(n/9)时为必胜状态,那么,必败状态只能转往必胜状态,所以,(ceil(n/9)/2)的只能是必败状态。倒推回去,就能知道先手处在必胜还是必败状态了。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #define LL __int64
    using namespace std;
    
    int main(){
    	LL n;
    	while(scanf("%I64d",&n)!=EOF){
    		bool win=false;
    		if(n==1){
    			printf("Stan wins.
    ");
    			continue;
    		}
    		while(n>1ll){
    			if(!win){
    				LL t=n/9;
    				if(t*9<n) n=t+1;
    				else n=t;
    			}
    			else{
    				LL t=n/2;
    				if(2*t<n) n=t+1;
    				else n=t;
    			}
    //			cout<<n<<endl;
    			win=!win;
    		}
    		if(win) printf("Stan wins.
    ");
    		else printf("Ollie wins.
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    同舟共济
    MQTT客户端
    Emgucv安装及使用
    Go生成UUID
    Go语言使用百度翻译api
    Go压缩文件
    Go语言的标准net库使用
    Go文件操作
    Go语言获取本地IP地址
    禅道使用规范
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/4396437.html
Copyright © 2011-2022 走看看