HDU 1536 SG函数模板
2016-07-30 19:23
555 查看
题目:
多堆石子,先手胜为L,后手胜为W,
思路:
SG函数:
SG[i]=0表示先手必败,否则必胜
有多堆石子,每次对SG[k]的值亦或(^)最终为0则必败,否则必胜
多堆石子,先手胜为L,后手胜为W,
思路:
SG函数:
SG[i]=0表示先手必败,否则必胜
有多堆石子,每次对SG[k]的值亦或(^)最终为0则必败,否则必胜
#include<cstring> #include<string> #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<queue> #include<vector> #include<map> #include<stack> #include<climits> #include<set> using namespace std; #define mod 1000000007 #define PI acos(-1.0) #define INF 0x3f3f3f3f typedef long long LL; const int N = 10008; int s[108],t; int sg ; bool Hash ; void sg_solve(int *s,int t,int n) //N求解范围 S[]数组是可以每次取的值,t是s的长度。 { int i,j; memset(sg,0,sizeof(sg)); for(i=1;i<=n;i++) { memset(Hash,0,sizeof(Hash)); for(j=0;j<t;j++) if(i - s[j] >= 0) Hash[sg[i-s[j]]] = 1; for(j=0;j<=N;j++) if(!Hash[j]) break; sg[i] = j; } } int main() { int i,j,n,m,h; while(scanf("%d",&t),t) { string ans=""; for(i=0;i<t;i++) scanf("%d",&s[i]); sg_solve(s,t,N); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&m); int res = 0; for(j=0;j<m;j++) { scanf("%d",&h); res ^= sg[h]; } ans+=res?'W':'L'; } cout<<ans<<endl; } return 0; }
相关文章推荐
- 在cmd下编译一个简单的servlet时出现程序包javax.servlet不存在
- 数据结构笔记--总结各种排序算法及其应用
- USB库STM32F0x2移植到STM32F070笔记
- Docker 构建 Java Web 开发环境——使用Dockerfile(二)
- 后缀数组 模板
- 【Web容器】Tomcat源码分析(3)-生命周期管理
- 如何让性能提升10万倍以上
- 使用枚举代替常量,简化工作!
- NN远程教育平台,一键安装,网址无缝对接
- Puppet使用方法总结
- continue,break控制流程
- get all Palindromes of a string
- Struts2批量验证(POC)
- 提升大数据数据分析性能的方法及技术(一)
- java设计模式_外观模式
- java夯实基础系列:面对对象原则
- 【Web容器】Tomcat源码分析(2)-server.xml文件的加载与解析
- JS中构造函数
- mysql的备份与恢复(使用自带命令行工具)
- Hadoop家族 路线图(转)