博弈论

  这题跟 BZOJ 1874 取石子游戏 差不多

  先暴力求出10000以内的SG函数(利用定义来求即可)

  然后每次询问直接将SG值异或起来即可……

 Source Code
Problem: User: sdfzyhy
Memory: 444K Time: 313MS
Language: G++ Result: Accepted Source Code //POJ 2960
#include<cstdio>
#include<cstring>
#define F(i,j,n) for(int i=j;i<=n;++i)
int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*=sign;
}
const int N=;
/******************tamplate*********************/
int f[N],s[];
bool mark[N];
void calsg(int n){
f[]=;
F(i,,){
memset(mark,,sizeof mark);
F(j,,n) if (i-s[j]>=)
mark[f[i-s[j]]]=;
F(j,,i) if(!mark[j]){ f[i]=j;break;}
}
}
int main(){
int n,m,k;
while(scanf("%d",&n)!=EOF && n){
F(i,,n) s[i]=getint();
m=getint();
calsg(n);
F(i,,m){
k=getint();
int ans=;
F(j,,k) ans^=f[getint()];
printf(ans ? "W" : "L");
}
printf("\n");
}
return ;
}

【POJ】【2960】S-Nim的更多相关文章

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

  10. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

随机推荐

  1. 简单的json传送数据

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  2. html5 拖曳功能的实现[转]

    HTML5中实现拖放操作,至少经过如下步骤1)设置被拖放对象元素的draggable属性设置为true2)编写与拖放有关的事件处理代码 事件 产生事件的元素 描述 dragstart 被拖拽物体 开始 ...

  3. Myeclipse安装svn插件(link方式)

    Myeclipse安装svn插件(link方式) 优点:1.离线安装2.非侵入式 演示版本 myeclipse--myeclipse8.6 svn--subeclipse-site-1.6.5.zip ...

  4. Qt学习总结-ui篇

    控件设置透明度: QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this); effect->setOpacity(0. ...

  5. Repost: Set Delivery Block on SO

    If SO is incomplete, then automatically set the delivery block on the SO header. as suggested by ear ...

  6. struts2中constant参数设置

    序号 方法 说明 1 <constant name="struts.i18n.encoding" value="UTF-8"/> 指定web应用默认 ...

  7. Viewport Resizer下载 谷歌前端自适应开发工具

    原文链接:http://www.phpbiji.cn/article/index/id/107/cid/6.html Viewport Resizer下载 谷歌前端自适应开发工具 在前端开发过程中,随 ...

  8. [转]高并发访问下避免对象缓存失效引发Dogpile效应

    避免Redis/Memcached缓存失效引发Dogpile效应 Redis/Memcached高并发访问下的缓存失效时可能产生Dogpile效应(Cache Stampede效应). 推荐阅读:高并 ...

  9. PHP连接SQL Server(sqlsrv)

    配置好php环境后,下载如下依赖包,解压目录选择php的ext目录,并在php.ini中加上(我的php版本为5.6) extension=php_pdo_sqlsrv_56_ts.dll exten ...

  10. apache泛域名的配置

    假设我们把服务器架设在:/home/www文件夹下面 我们有应用A和B,对应的文件目录为A:/home/www/testAB:/home/www/testB 设置proxy_module让网站支持泛域 ...