zoukankan      html  css  js  c++  java
  • 洛谷P1290 欧几里德的游戏 数学 博弈论 模拟

    洛谷P1290 欧几里德的游戏

    数学 博弈论 模拟

    这道题我们因为当 x 大于 y 时 你也只能在合法范围 内取 1 个 y 两个 y
    也就是说 能取的y大于等于2时,则你本质不同的取法共有两种,此时你必定获胜,
    因为本质不同,而在最优策略下,则说明胜利者也不同,也就是说这时候你可以
    决定自己的输赢 ,我们称这种必胜局为 v 局
    2、但是如果 v 局后面还有v 局怎么办,这个不必担心,因为先拿到 v局的人,
    有两种本质不同的取法,也就是说 他可以控制自己下次必定拿到 v 局,这样就 能确保胜利了

    所以说谁先到 x>=2*y 或者 y==0 的局面谁就胜利了

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <string>
     6 #include <iostream>
     7 #include <iomanip>
     8 using namespace std ; 
     9 
    10 int T,x,y,now,t ; 
    11 
    12 inline int work(int x,int y) 
    13 {
    14     now = 1 ; 
    15     while( 1 ) 
    16     {
    17         now^=1 ;  
    18         if( x >= 2*y ) return now ; 
    19         t = x ; x = y ;  y = t % y ;  
    20         if(y==0) return now ; 
    21     }
    22 }
    23 
    24 int main() 
    25 {
    26     scanf("%d",&T) ; 
    27     while(T--) 
    28     {
    29         scanf("%d%d",&x,&y) ; 
    30         if(x < y) swap(x,y) ; 
    31         work(x,y) ; 
    32         if( now==0 )
    33             printf("Stan wins
    ") ; 
    34         else
    35             printf("Ollie wins
    ") ; 
    36             
    37     }
    38     return 0 ; 
    39 }

    另外还有一种做法是用黄金比来做
    黄金比例

    如果两个数相等,或者两数之比大于斐 波拉契数列相邻两项之比的极限((sqrt(5)+1)/2),则先手胜,否则后手胜。

    我是这样理解的 设 x 永远大于 y
    那么 若x 与 y 的比值 等于 黄金比的倒数 换句换说 就是 y 与x 的比值等于黄金比时 则 x 与 y 的比值永远不会变

    这时候我们的判断条件还是一样 但稍有不同 如果比值 到 2 则先手胜 若比值 为 0.5 则后手胜
    这时候 我们把黄金比称为平衡状态 x增大则破坏了平衡 使 比值趋向于 2
    于是 先手胜 同理如果y变大 则 比值趋向0.5 所以后手胜
    所以我们直接比较 比值与黄金比的关系就行了
    当然,我的理解有许多是感性的理解,并没有理性的证明,纯属自己瞎理解,
    如果哪位大神有严格证明的话,欢迎来告诉我


    代码

     1 #include<set>  
     2 #include<map>  
     3 #include<list>  
     4 #include<queue>  
     5 #include<stack>  
     6 #include<string>  
     7 #include<math.h>  
     8 #include<time.h>  
     9 #include<vector>  
    10 #include<bitset>  
    11 #include<memory>  
    12 #include<utility>  
    13 #include<stdio.h>  
    14 #include<sstream>  
    15 #include<iostream>  
    16 #include<stdlib.h>  
    17 #include<string.h>  
    18 #include<algorithm> 
    19 #define LL unsigned long long  
    20 using namespace std;
    21 int main()
    22 {
    23     int i,c,a,b,m,n,k;
    24     cin>>c;
    25     for (i=1;i<=c;i++)
    26     {
    27         scanf("%d %d",&m,&n);
    28         if (m==n) printf("Stan wins
    ");
    29         else
    30         {
    31             if (m<n)
    32               {
    33                 if ((n*1.0)/m>(sqrt(5)+1)/2)
    34                     printf("Stan wins
    ");
    35                 else   
    36                     printf("Ollie wins
    ");
    37             }
    38             else 
    39             {
    40                 if ((m*1.0)/n>((sqrt(5)+1)/2))
    41                     printf("Stan wins
    "); 
    42                 else   
    43                     printf("Ollie wins
    ");
    44             }
    45        }
    46     }
    47     return 0;
    48 } 
  • 相关阅读:
    套接口编程理论基础:正常启动
    套接口编程理论基础:服务器进程终止
    套接口编程理论基础:处理SIGCHLD信号
    分区表、分区索引
    IPC通信:Posix消息队列读,写
    IPC通信:Posix消息队列的创建,关闭,删除
    RBAC的资料
    关于RBAC的学习资料
    RSS你会用了吗?答曰:不会
    RBAC的资料
  • 原文地址:https://www.cnblogs.com/third2333/p/7082030.html
Copyright © 2011-2022 走看看