zoukankan      html  css  js  c++  java
  • poj 2311 AND hdu 2869

    hdu 2869 Paper Cutting Game

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2869

    View Code
     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <string>
     6 #include <stdlib.h>
     7 #include <algorithm>
     8 using namespace std;
     9 typedef long long LL;
    10 const LL Mod= 1e9+7;
    11 int N, M, tot; 
    12 int p[100], a[1000];
    13 void getp( )
    14 {
    15     p[0]=2;
    16     for( int i=3; i<40; i+=2 ){
    17         if( !a[i] ){
    18             for( int j=i+i; j<1000; j+=i )
    19                 a[j]=1;
    20         }
    21     }
    22     for( int j=3; j<1000; j+=2 )
    23         if( !a[j] )
    24             p[++tot]=j;
    25 }
    26 int AC( int x )
    27 {
    28     int ans=0; 
    29     for( int i=0; p[i]&&p[i]<=x; ++ i ){
    30         while( x%p[i]==0 ){
    31             ans++; 
    32             x/=p[i]; 
    33         }
    34     } 
    35     return ans;
    36 }
    37 int main( )
    38 {
    39     getp();
    40     while( scanf("%d%d", &N,&M)==2 ){
    41         if( AC( N )<=AC(M) )puts( "Lose" );
    42         else puts( "Win" );
    43     } 
    44     return 0;
    45 }


    poj 2311

    链接: http://poj.org/problem?id=2311

    SG应用的场景

     游戏有两个人参与,二者轮流做出决策。且这两个人的决策都对自己最有利。 

      当有一人无法做出决策时游戏结束,无法做出决策的人输。

      无论二者如何做出决策,游戏可以在有限步内结束。 

      游戏中的同一个状态不可能多次抵达。且游戏不会有平局出现。 

      任意一个游戏者在某一确定状态可以作出的决策集合只与当前的状态有关,而与游戏者无关。

    View Code
     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <string>
     6 #include <stdlib.h>
     7 #include <algorithm>
     8 using namespace std;
     9 typedef long long LL;
    10 const LL Mod= 1e9+7;
    11 int N, M; 
    12 int sg[205][205];
    13 int mex(int x, int y)
    14 {
    15     if( sg[x][y]!=-1 )return sg[x][y];
    16     bool re[205]={0};
    17     int i;
    18     for( i=2;i<=x/2;++i ){
    19         re[mex(i, y)^mex(x-i, y)]=1;
    20     }
    21     for( i=2;i<=y/2;++i ){
    22         re[mex(x, i)^mex(x, y-i)]=1;
    23     }
    24     i=0;
    25     while( re[i] )++i;
    26     return sg[x][y]=i;
    27 }
    28 int main( )
    29 {
    30     memset( sg, -1 , sizeof sg);
    31     sg[2][2]=sg[2][3]=sg[3][2]=0;
    32     while( scanf("%d%d", &N,&M)==2 ){
    33         if( N==1 || M==1 )puts("LOSE");
    34         else if( mex( N, M ) )puts( "WIN" );
    35         else puts("LOSE");
    36     } 
    37     return 0;
    38 }
  • 相关阅读:
    JAVA调用WebService总结
    关于购物车的想法
    ASP.NET中初试Ajax
    转帖:从FxCop归纳出来的一些规范建议
    数据结构(二叉树)C#描述
    FormView控件和DetailsGridView控件实现MasterSlave
    在.NET中使用MySql数据库
    Oracle学习总结1
    Oracle学习总结2
    关于字符匹配所引起的的问题
  • 原文地址:https://www.cnblogs.com/jian1573/p/3052565.html
Copyright © 2011-2022 走看看