http://www.lydsy.com/JudgeOnline/problem.php?id=3404

写挫好几次。。。。

裸的博弈论即可。。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. #define rep(i, n) for(int i=0; i<(n); ++i)
  10. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  11. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  12. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  13. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  14. #define CC(i,a) memset(i,a,sizeof(i))
  15. #define read(a) a=getint()
  16. #define print(a) printf("%d", a)
  17. #define dbg(x) cout << #x << " = " << x << endl
  18. #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
  19. inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
  20. inline const int max(const int &a, const int &b) { return a>b?a:b; }
  21. inline const int min(const int &a, const int &b) { return a<b?a:b; }
  22.  
  23. const int N=1000005;
  24. bool f[N], vis[N];
  25. bool dfs(int x) {
  26. if(vis[x]) return f[x];
  27. if(x==0) return 0;
  28. vis[x]=1;
  29. int t=x, mx=0, mn=10;
  30. while(t) {
  31. int k=t%10;
  32. t/=10;
  33. if(k) mx=max(mx, k), mn=min(mn, k);
  34. }
  35. if(!dfs(x-mn)) return f[x]=1;
  36. if(!dfs(x-mx)) return f[x]=1;
  37. return f[x]=0;
  38. }
  39. int main() {
  40. int n=getint();
  41. while(n--) {
  42. int ans=dfs(getint());
  43. ans?puts("YES"):puts("NO");
  44. }
  45. return 0;
  46. }

Description

    贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她.
    游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游
戏规则是这样的:双方轮流操作,将当前的数字减去一个数,这个数可以是当前 数字的最大数码,也可以是最小的非0数码.比如当前的数是3014,操作者可以减去1变成3013,也可以减去4变成3010.若干次操作之后,这个数字 会变成0.这时候不能再操作的一方为输家.    贝茜总是先开始操作.如果贝茜和约翰都足够聪明,执行最好的策略.请你计算最后的赢家.
    比如,一场游戏开始于13.贝茜将13减去3变成10.约翰只能将10减去1变成9.贝茜再将9减去9变成0.最后贝茜赢.

Input

    第1行输入一个整数G,之后G行一行输入一个Ni.

Output

 
    对于每一场游戏,若贝茜能赢,则输出一行“YES”,否则输幽一行“NO”

Sample Input

2
9
10

Sample Output

YES
NO

HINT

  1. For the first game, Bessie simply takes the number 9 and wins.
  2. For the second game, Bessie must take 1 (since she cannot take 0), and then
  3. FJ can win by taking 9.

Source

【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)的更多相关文章

  1. BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)

    一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...

  2. 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 72  Solved ...

  3. BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solved ...

  4. 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏

    #include<cstring> #include<cstdio> #include<algorithm> #include<set> using n ...

  5. 【BZOJ】【3404】【USACO2009 Open】Cow Digit Game又见数字游戏

    博弈论 Orz ZYF 从前往后递推……反正最大才10^6,完全可以暴力预处理每个数的状态是必胜还是必败(反正才两个后继状态),然后O(1)查询……我是SB /******************** ...

  6. BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5 ...

  7. BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )

    直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...

  8. BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...

  9. BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...

随机推荐

  1. win10下JDK安装,配置环境变量后出现error:could not open '...jvm.cfg'

        分析: 大多是安装jdk的时候在注册表里注册过,打开注册表查看里面如下三个文件( Java Development Kit,Java Plug-in,Java Runtime Environm ...

  2. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何在初始化的时候写入参数

    最常见的是定义一个全局变量,然后跟对应的变量绑定,比如我定义了一个SINT型的变量ControlWord 数值是8,定义好之后编译一下,可以发现PLC程序中或多出来这个变量(MAIN.ControlW ...

  3. [转]bing壁纸天天换 初识shell魅力

    原文链接:http://www.cnblogs.com/atskyline/p/3679522.html 原文的程序跑在window上,curl的使用不太一样,想要获取的图片也不太一样.修改后的代码如 ...

  4. Why do Antennas Radiate?

    Obtaining an intuitive idea for why antennas radiate is helpful in understanding the fundamentals of ...

  5. python xml.etree.ElementTree解析xml文件获取节点

    <?xml version = "1.0" encoding = "utf-8"?> <root> <body name=&quo ...

  6. 面向对象知识点之statickeyword的使用

    <?php /*由static定义的属性和方法称为静态成员和静态方法.static定义的属性和方法是属于类的,在对象之间共享.*/ /*比如能够通过定义一个静态变量来统计类实例化了多少个对象*/ ...

  7. iOS UITableView获取特定位置的cell

    代码地址如下:http://www.demodashi.com/demo/13307.html 一.tableView双级联动 以上两种效果比较类似,实现的关键在于都是需要获得在滑动过程中滑动到tab ...

  8. UIScrollerView当前显示3张图

    代码地址如下:http://www.demodashi.com/demo/11173.html WSLScrollView 功能描述:这是在继承UIView的基础上利用UIScrollerView进行 ...

  9. setjmp与longjmp

    在C中有时我们会使用goto语句用于运行跳转,可是不能跨越函数 #include <stdio.h> void func2() { int num = 0; dst2: if (num & ...

  10. (总结)Linux下su与su -命令的本质区别

    http://www.uplook.cn/index-Index-show-view15192.html大部分Linux发行版的默认账户是普通用户,而更改系统文件或者执行某些命令,需要root身份才能 ...