题目:(luogu翻译错的很多)

Alice和Bob玩游戏,每人有8张牌,牌的值为0~4。每一轮当前玩家选择自己的牌A和对手的牌B,然后将A的值变为( A + B )%5,其中A和B都不是0。

当一个人手牌全为0时他就赢了。

T(T<=1e5)组询问,求最后谁赢了,如果都没赢输出Deal。(两个人都是最优方案)

题解:

博弈搜索。

只不过本题有无解情况,因此dfs会卡(应该是我太弱了)。所以考虑用bfs,相当于dfs中直接回溯。

代码:

#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[][][][],cnt;
int T;
int dp[],ind[];//first:second
void init()
{
for(int a=;a<=;a++)
for(int b=;a+b<=;b++)
for(int c=;a+b+c<=;c++)
for(int d=;a+b+c+d<=;d++)
num[a][b][c][d]=++cnt;
}
int tn(int a,int b)
{
return (a-)*cnt+b-;
}
int cg(int a[],int b[])
{
return tn(num[a[]][a[]][a[]][a[]],num[b[]][b[]][b[]][b[]]);
}
int gt(int a[])
{
int ret = ;
for(int i=;i<=;i++)ret+=(a[i]!=);
return ret;
}
struct node
{
int a[],b[];
int aa(){return num[a[]][a[]][a[]][a[]];}
int bb(){return num[b[]][b[]][b[]][b[]];}
int cc(){return tn(aa(),bb());}
node df()
{
node ret;
for(int i=;i<=;i++)ret.a[i]=b[i],ret.b[i]=a[i];
return ret;
}
}tmp;
queue<node>q;
int a0[],b0[];
void dfsb(int dep,int sum)
{
if(dep==)
{
int c = cg(a0,b0),ga=gt(a0),gb=gt(b0);
ind[c] = ga*gb;
if(!(ga*gb))
{
if(!ga)dp[c]=;
else dp[c]=;
tmp.a[]=-a0[]-a0[]-a0[]-a0[],tmp.a[]=a0[],tmp.a[]=a0[],tmp.a[]=a0[],tmp.a[]=a0[];
tmp.b[]=-b0[]-b0[]-b0[]-b0[],tmp.b[]=b0[],tmp.b[]=b0[],tmp.b[]=b0[],tmp.b[]=b0[];
q.push(tmp);
}
return ;
}
for(b0[dep]=;b0[dep]+sum<=;b0[dep]++)
dfsb(dep+,sum+b0[dep]);
}
void dfsa(int dep,int sum)
{
if(dep==){dfsb(,);return ;}
for(a0[dep]=;a0[dep]+sum<=;a0[dep]++)
dfsa(dep+,sum+a0[dep]);
}
void bfs()
{
while(!q.empty())
{
tmp = q.front();
q.pop();
node v = tmp.df();
for(int j=;j<=;j++)
{
if(!v.b[j])continue;
for(int i=;i<=;i++)
{
if(!v.a[i]||(i-j+)%==)continue;
v.a[i]--;
v.a[(i-j+)%]++;
int c = v.cc(),c0 = tmp.cc();
if(!ind[c])
{
v.a[i]++;
v.a[(i-j+)%]--;
continue;
}
if(dp[c0]==)
{
dp[c]=;
ind[c]=;
q.push(v);
v.a[i]++;
v.a[(i-j+)%]--;
continue;
}else if(!dp[c0])
{
dp[c]=;
}
ind[c]--;
v.a[i]++;
v.a[(i-j+)%]--;
if(ind[c])continue;
if(!dp[c])dp[c]=;
else dp[c]=;
v.a[i]--;
v.a[(i-j+)%]++;
q.push(v);
v.a[i]++;
v.a[(i-j+)%]--;
}
}
}
}
int typ;
int main()
{
init();
dfsa(,);
bfs();
scanf("%d",&T);
while(T--)
{
memset(a0,,sizeof(a0));
memset(b0,,sizeof(b0));
scanf("%d",&typ);
for(int x,i=;i<=;i++)
{
scanf("%d",&x);
a0[x]++;
}
for(int x,i=;i<=;i++)
{
scanf("%d",&x);
b0[x]++;
}
int c = typ?cg(b0,a0):cg(a0,b0);
int ans = dp[c];
if(!ans)
{
printf("Deal\n");
}else
{
if((ans-)^typ)
{
printf("Bob\n");
}else
{
printf("Alice\n");
}
}
}
return ;
}

CF919F A Game With Numbers的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

随机推荐

  1. HDU-ACM“菜鸟先飞”冬训系列赛——第9场

    Problem A 题意 一对兔子每月生一对兔子,兔子在\(m\)月后成熟,问\(d\)月后有多少兔子 分析 可以发现,第i月的兔子数量取决于第i-1月与i-m月,故 \(a[i]=a[i-1]+a[ ...

  2. HDU-ACM“菜鸟先飞”冬训系列赛——第8场(1004)

    Problem D Time Limit : 3000/3000ms (Java/Other) Memory Limit : 65535/102400K (Java/Other) Problem De ...

  3. 扭曲效果 效率优化 GrapPass,CommandBuffer对比

    屏幕图像捕捉: Shader的GrabPass GrabPass可以很方便地捕获当前渲染时刻的FrameBuffer中的图像. 其原理就是从当前FrameBuffer中copy一份纹理,通过SetTe ...

  4. c语言程序设计案例教程(第2版)笔记(五)-软件开发基础知识

    零散知识点: 软件的主要特征 软件是一种逻辑产品,而不是有型的物质: 软件需要设计.开发,但不是传统意义上的产品制造: 软件不会磨损,但软件需要维护,即:修改代码或增加模块: 虽然软件行业正在向基于组 ...

  5. 进击的Python【第七章】:python各种类,反射,异常处理和socket基础

    Python的高级应用(三)面向对象编程进阶 本章学习要点: 面向对象高级语法部分 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 一.面向对象高级语法部分 静态方法 ...

  6. [POI2009]救火站Gas

    Description 给你一棵树,现在要建立一些消防站,有以下要求: 1. 消防站要建立在节点上,每个节点可能建立不只一个消防站. 2. 每个节点应该被一个消防站管理,这个消防站不一定建立在该节点上 ...

  7. 贪心 HDOJ 5385 The Path

    题目传送门 /* 题意:给一张图和一些有向边,问如何给边赋值使得d1 < d2 < .. < dx > ,,,< ddn 贪心:左边从2开始,右边从n开始,每次选择未标记 ...

  8. 转-关于UIView的autoresizingMask属性的研究

    在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum  ...

  9. 437 Path Sum III 路径总和 III

    给定一个二叉树,二叉树的每个节点含有一个整数.找出路径和等于给定数的路径总数.路径不需要从根节点开始,也不需要在叶节点结束,当路径方向必须是向下的(只从父节点到子节点).二叉树不超过1000个节点,节 ...

  10. MVP架构模式

    概念解释 MVP是Model(数据) View(界面) Presenter(表现层)的缩写,它是MVC架构的变种,强调Model和View的最大化解耦和单一职责原则 Model:负责数据的来源和封装, ...