luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论
每个位置的瓶子中的每个石子是一个独立的游戏
只要计算出他们的\(sg\)值即可
至于方案数,反正不多\(n^3\)暴力枚举即可
反正怎么暴力都能过啊
复杂度\(O(Tn^3)\)
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
#define gc getchar
inline int read() {
int p = 0, w = 1; char c = gc();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = gc(); }
while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
return p * w;
}
int n, sg[25], mex[105];
inline void get_sg() {
sg[n] = 0;
drep(i, n - 1, 1) {
memset(mex, 0, sizeof(mex));
rep(j, i + 1, n) rep(k, j, n)
mex[sg[j] ^ sg[k]] = 1;
rep(j, 0, 100)
if(!mex[j]) { sg[i] = j; break; }
}
}
int main() {
int T = read();
while(T --) {
n = read(); get_sg();
int SG = 0;
rep(i, 1, n) SG ^= (read() & 1) * sg[i];
if(!SG) {
printf("-1 -1 -1\n");
printf("0\n"); continue;
}
int ans = 0, flag = 0;
rep(i, 1, n) rep(j, i + 1, n) rep(k, j, n)
if((SG ^ sg[i] ^ sg[j] ^ sg[k]) == 0) {
if(!flag) { printf("%d %d %d\n", i - 1, j - 1, k - 1); flag = 1; }
ans ++;
}
printf("%d\n", ans);
}
return 0;
}
luoguP3185 [HNOI2007]分裂游戏 枚举 + 博弈论的更多相关文章
- [bzoj1188][HNOI2007]分裂游戏_博弈论
分裂游戏 bzoj-1188 HNOI-2007 题目大意:题目链接. 注释:略. 想法: 我们发现如果一个瓶子内的小球个数是奇数才是有效的. 所以我们就可以将问题变成了一个瓶子里最多只有一个球球. ...
- [BZOJ1188][HNOI2007]分裂游戏(博弈论)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1188 分析: 设SG[i]表示一个石子在位置i上的SG值 这个很容易暴力求,因为i的后 ...
- [BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】
题目链接:BZOJ - 1188 题目分析 我们把每一颗石子看做一个单个的游戏,它的 SG 值取决于它的位置. 对于一颗在 i 位置的石子,根据游戏规则,它的后继状态就是枚举符合条件的 j, k.然后 ...
- bzoj1188 [HNOI2007]分裂游戏 博弈论 sg函数的应用
1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 973 Solved: 599[Submit][Status ...
- bzoj 1188 [HNOI2007]分裂游戏 SG函数 SG定理
[HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1394 Solved: 847[Submit][Status][Dis ...
- bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)
1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 733 Solved: 451[Submit][Status ...
- 【BZOJ1188】分裂游戏(博弈论)
[BZOJ1188]分裂游戏(博弈论) 题面 BZOJ 洛谷 题解 这道题目比较神仙. 首先观察结束状态,即\(P\)状态,此时必定是所有的豆子都在最后一个瓶子中. 发现每次的转移一定是拿出一棵豆子, ...
- 【博弈论】【SG函数】【枚举】bzoj1188 [HNOI2007]分裂游戏
因为第i个瓶子里的所有豆子都是等价的,设sg(i)表示第i个瓶子的sg值,可以转移到sg(j)^sg(k)(i<j<n,j<=k<n)的状态. 只需要考虑豆子数是奇数的瓶子啦, ...
- BZOJ1188:[HNOI2007]分裂游戏(博弈论)
Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏.该游戏的规则试:共有n个瓶子,标号为0,1,2.....n-1,第i个瓶子中装有p[i]颗巧克力豆,两个人轮流取豆子,每一轮每人选择3个 ...
随机推荐
- [转]Laplace算子和Laplacian矩阵
1 Laplace算子的物理意义 Laplace算子的定义为梯度的散度. 在Cartesian坐标系下也可表示为: 或者,它是Hessian矩阵的迹: 以热传导方程为例,因为热流与温度的梯度成正比,那 ...
- Linux中断处理驱动程序编写【转】
转自:http://blog.163.com/baosongliang@126/blog/static/1949357020132585316912/ 本章节我们一起来探讨一下Linux中的中断 中断 ...
- linux系统编程之信号:信号发送函数sigqueue和信号安装函数sigaction
信号发送函数sigqueue和信号安装函数sigaction sigaction函数用于改变进程接收到特定信号后的行为. sigqueue()是比较新的发送信号系统调用,主要是针对实时信号提出的(当然 ...
- nginx_upstream_check_module-master对nginx的后端机器进行健康状态检查报403错误【转】
在nginx.conf配置文件中 在server添加 location /nstatus { check_status; access_log off; #allow 192.168.2.11; #d ...
- 学习记录:mongodb里插入整型值
=============================================== 2018/1/24_第1次修改 ccb_warlock == ...
- Django 2.0.3安装-压缩包方式
OS:Windows 10家庭中文版,CPU:Intel Core i5-8250U Python版本:Python 2.7,Python 3.6 Django版本:2.0.3(最新2.0.5) 解压 ...
- python基础--re模块
常用正则表达式符号 '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r& ...
- linux定时任务-cron
/sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 ...
- redis持久化的两种方式
redis是一个内存型数据库.当redis服务器重启时,数据会丢失.我们可以将redis内存中的数据持久化保存到硬盘的文件中. redis持久化有两种机制.RDB与AOF.默认方式是RDB. 1.RD ...
- MyBatis3.4.0以上的分页插件错误:Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.stateme
错误: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named p ...