题意:每次可以选择n种操作,玩m次,问谁必胜。c堆,每堆数量告诉。

题意:sg—NIM系列博弈模板题

把每堆看成一个点,求该点的sg值,异或每堆sg值。

将多维转化成一维,性质与原始NIM博弈一样。

  1. // #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <sstream>
  6. #include <string>
  7. #include <algorithm>
  8. #include <list>
  9. #include <map>
  10. #include <vector>
  11. #include <queue>
  12. #include <stack>
  13. #include <cmath>
  14. #include <cstdlib>
  15. // #include <conio.h>
  16. using namespace std;
  17. #define clc(a,b) memset(a,b,sizeof(a))
  18. #define inf 0x3f3f3f3f
  19. #define lson l,mid,rt<<1
  20. #define rson mid+1,r,rt<<1|1
  21. const int N = ;
  22. const int MOD = 1e9+;
  23. #define LL long long
  24. #define mi() (l+r)>>1
  25. double const pi = acos(-);
  26.  
  27. void fre() {
  28. freopen("in.txt","r",stdin);
  29. }
  30.  
  31. // inline int r() {
  32. // int x=0,f=1;char ch=getchar();
  33. // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
  34. // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
  35. // }
  36. int n,m;
  37. int a[N];
  38. int sg[N];
  39. int mex(int x){
  40. int g[];
  41. clc(g,);
  42. for(int i=;i<n;i++){
  43. int res=x-a[i];
  44. if(res<) break;
  45. if(sg[res]==-)
  46. sg[res]=mex(res);
  47. g[sg[res]]=;
  48. }
  49. for(int i=;i<;i++){
  50. if(!g[i])
  51. return i;
  52. }
  53. }
  54.  
  55. int main(){
  56. // fre();
  57. while(~scanf("%d",&n),n){
  58. // clc(g,0);
  59. clc(sg,-);
  60. sg[]=;
  61. for(int i=;i<n;i++)
  62. scanf("%d",&a[i]);
  63. sort(a,a+n);
  64. scanf("%d",&m);
  65. while(m--){
  66. int c;
  67. int s=;
  68. scanf("%d",&c);
  69. while(c--){
  70. int x;
  71. scanf("%d",&x);
  72. if(sg[x]==-)
  73. sg[x]=mex(x);
  74. // cout<<sg[x]<<endl;
  75. // system("pasuse");
  76. s^=sg[x];
  77. }
  78. // cout<<s<<endl;
  79. if(s==)
  80. printf("L");
  81. else
  82. printf("W");
  83. }
  84. printf("\n");
  85. }
  86. return ;
  87. }

HDU 1536 sg-NIM博弈类的更多相关文章

  1. hdu 1536 sg (dfs实现)

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. HDU 1536 sg函数

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. hdu 1536 SG函数模板题

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  4. HDU 1848 SG函数博弈

    Fibonacci again and again Problem Description   任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...

  5. HDU 1907 John nim博弈变形

    John Problem Description   Little John is playing very funny game with his younger brother. There is ...

  6. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  7. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  8. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  9. hdu 1730 Nim博弈

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先 ...

随机推荐

  1. s3cmd的安装与使用

     s3cmd 是一款 Amazon S3 命令行工具.它不仅能上传.下载.同步,还能设置权限,下面是完整的安装使用指南. 主要是还是用来储存日志文件或者其他什么资料. https://wangyan. ...

  2. ios开发--高德地图SDK使用简介

    高德LBS开放平台将高德最专业的定位.地图.搜索.导航等能力,以API.SDK等形式向广大开发者免费开放.本章节我们来简单学习一下如何使用它的定位及地图SDK. 一.相关框架及环境配置 地图SDK 对 ...

  3. Orcle数据库查询练习复习:二

    一.题目 1.找出所有成绩均低于80的学生姓名 select sname from student where sid in( ) select sname from student where si ...

  4. UDP丢包和无序 问题的解决方法

    最近在做一个项目,在这之前,做了个验证程序. 发现客户端连续发来1000个1024字节的包,服务器端出现了丢包现象. 纠其原因,是服务端在还未完全处理掉数据,客户端已经数据发送完毕且关闭了. 我用过s ...

  5. cdev_init函数

    linux-2.6.22/include/linux/cdev.hstruct cdev {   struct kobject kobj;          // 每个 cdev 都是一个 kobje ...

  6. maven - setting.xml

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  7. LICEcap 简洁易用的动画屏幕录制软件

    LICEcap 简洁易用的动画屏幕录制软件 LICEcap 捕捉屏幕的区域并保存为gif动画(便于网络发布)或lcf格式(见下). LICEcap 直观易用,功能灵活,支持 Windows 和 OSX ...

  8. 添加gif效果图

    1.贴加第三方包 http://blog.csdn.net/iamlazybone/article/details/5972234 2. <FrameLayout android:id=&quo ...

  9. Android Dialog使用举例

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...

  10. chrome 远程调试(转)

    http://www.tuicool.com/articles/ZJfeAzi 由于 appspot.com被墙,一般调试不成功. 随着智能手机的普及,移动设备的浏览器功能越来越强大,我们用手机上网时 ...