HDU 5724 Chess(博弈&状压)_chess的思考深度-程序员宅基地

技术标签: =====博弈=====  博弈  2016多校联赛  状压  

题目:
Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.

Input
Multiple test cases.

The first line contains an integer T(T≤100), indicates the number of test cases.

For each test case, the first line contains a single integer n(n≤1000), the number of lines of chessboard.

Then n lines, the first integer of ith line is m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20) followed, the position of each chess.

Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.

Sample Input
2
1
2 19 20
2
1 19
1 18

Sample Output
NO
YES

2016多校第一场的博弈题,作为一个不会状压的鶸今天看到题解赶紧滚去学习了下,果然博大精深,比赛时的求sg值的思路有问题所以GG了,结合网上大神思路改了下:

    利用状压的思想求出当前状态的所有后继状态并根据他们的sg值确定当前状态的sg值;

    因为移动后表示状态的数必然变小所以正向遍历;

AC代码…:

#include <bits/stdc++.h>
#define rep(i,j,k) for (int i = j; i <= k; i++)
using namespace std;
int sg[(1<<20)+100];

int get_sg (int i) {
    int h[25];
    memset(h, 0, sizeof(h));
    int last = -1;
    rep(j, 0, 19) {
        if(!((i>>j)&1)) last = j; //依次找到一个0位置,标记
        else { //找到1位置
            if(last!=-1){
                h[sg[i^(1<<j)^(1<<last)]] = 1; //标记后继状态(将标记的0和1互换后的状态)
            }
        }
    }
    int j = 0;
    while(h[j])
        j++;
    return j;  //统计获得sg值
}
int main(){
    int t, n, m, x;
    rep(i, 1, (1<<20))
        sg[i] = get_sg(i);
    scanf("%d",&t);
    while(t--){
        scanf("%d", &n);
        int ans = 0;
        rep(i, 1, n) {
            scanf("%d", &m);
            int t=0;
            rep(i, 1, m){
                scanf("%d", &x);
                t ^= 1<<(20-x); //计算当前的状态
            }
            ans ^= sg[t];
        }
        puts(ans ? "YES" : "NO");
    }
    return 0;
}

太TM菜了,,滚去做题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/CerberuX/article/details/51967357

智能推荐

什么是128陷阱?-程序员宅基地

文章浏览阅读248次。什么是128陷阱?

Linux系统中CPU占用率飙升?Java应用排查实战来了!_linux服务器cpu占用率过高-程序员宅基地

文章浏览阅读1k次,点赞28次,收藏10次。CPU的持续高负载会严重影响业务系统的正常运行,甚至可能导致服务中断,造成不可估量的损失。命令的输出中,重点关注PID(进程ID)、USER(进程所有者)、PR(进程优先级)、NI(nice值)、VIRT(虚拟内存使用量)、RES(物理内存使用量)、SHR(共享内存大小)、S(进程状态)、%CPU(占用的CPU使用率)和%MEM(占用的内存使用率)等列。需要注意的是,这一步通常需要与Java开发人员一起排查,因为堆栈信息中可能包含大量的业务代码和框架代码,需要有一定的业务知识和框架知识才能准确理解。_linux服务器cpu占用率过高

SpringBoot 集成 Kafka (SSL证书)_springboot kafka ssl-程序员宅基地

文章浏览阅读1.3k次。SpringBoot 集成 Kafka (SSL证书)_springboot kafka ssl

AOP常用的几种增强方式,各自的特点(代码辅助)_aop切面有那些功能增强-程序员宅基地

文章浏览阅读194次。spring-AOP 的实现:_aop切面有那些功能增强

PostgreSQL 循环遍历结果集_pg数据库遍历查询结果-程序员宅基地

文章浏览阅读2k次。PostgreSQL 循环 结果集_pg数据库遍历查询结果

桂林电子科技 计算机科学与技术,桂林电子科技大学计算机科学与技术专业-程序员宅基地

文章浏览阅读270次。桂林电子科技大学计算机科学与技术专业计算机科学与技术专业解读一、培养目标 培养德、智、体全面发展,具有计算机科学与计算机工程领域系统、扎实的理论基础,知识结构合理,具有创新能力和国际竞争力的高素质的科技人才。本专业的学生在信息的获取、传递、处理及应用等方面具有较宽广的专业知识、掌握现代计算机科学及工程中计算机硬件和计算机系统软件的基本原理、计算机应用技术,并具有较强的工程实践能力,具备设计、..._桂林电子科技大学程序设计与问题求解

随便推点

NLP 使用Word2vec实现文本分类_word2vec 使用-程序员宅基地

文章浏览阅读683次,点赞3次,收藏6次。【代码】NLP 使用Word2vec实现文本分类。_word2vec 使用

Bootstrap popover 实现鼠标移入移除显示隐藏功能_a-popover 隐藏-程序员宅基地

文章浏览阅读8.4k次。该段js代码可实现 popover 下鼠标移入移除时显示、隐藏 popover 提示信息功能var strContent = 'name}}">'+ ''+ ''+ '小标题'+ '张三 管理员'+_a-popover 隐藏

C语言最大公约数及最小公倍数讲解_c语言头歌函数第六关公约公倍数-程序员宅基地

文章浏览阅读635次。代码如下:#include<stdio.h>int main(void){ int m,n,t,p; scanf("%d %d",&m,&n); if(n > m){ t=n; n=m; m=t; } p = m * n; for(int i = n;i > 0;i--){ if(m..._c语言头歌函数第六关公约公倍数

Python3日常:一键灭掉Chrome浏览器software_reporter_tool.exe进程_python 所有浏览器进程-程序员宅基地

文章浏览阅读1.7k次。Chrome每次自动更新后,出现software_reporter_tool.exe占CPU的问题在日常使用Chrome经常遇到风扇突然狂转的问题,网上搜了一下才发现Chrome目录下会有这样一个程序software_reporter_tool.exe在狂吃CPU(文件位置一般在C:\Users\name\AppData\Local\Google\Chrome\User Data\SwRepor..._python 所有浏览器进程

零基础学编程,选PHP还是Python?_零基础学php phython到底哪个好-程序员宅基地

文章浏览阅读1k次。对于许多想学编程的人,零基础选择学习哪个课程总是很纠结?今天小编就给大家解疑答惑。在这两门语言中,小编建议大家选择Python。为什么要大家选择Python呢?看看Python与PHP的对比,你就明白了。Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。可单独使用,也可作为django等框架的组成部分。具有极高的可读性和灵活性。2017年Python被选为大学院校计算机专业入门语..._零基础学php phython到底哪个好

linux学习——华农决战Linux(1)IDEA导出项目参考_决战linux scau-程序员宅基地

文章浏览阅读136次。idea 导出war包<https://blog.csdn.net/qq_34545192/article/details/62428191>_决战linux scau

推荐文章

热门文章

相关标签