CF919F A Game With Numbers
题目:(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的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- ObjectInputStream与ObjectOutputStream类实现对象的存取
1. ObjectInputStream与ObjectOutputStream类所读写的对象必须实现Serializable接口,对象中的transient和static类型成员变量不会被读取和写入 ...
- P3158 [CQOI2011]放棋子
传送门 题解(因为公式太多懒得自己抄写一遍了--) //minamoto #include<bits/stdc++.h> #define ll long long #define R re ...
- 5 分钟掌握 JS 实用窍门技巧,帮你快速撸码--- 删除数组尾部元素、E6对象解构、async/await、 操作平铺嵌套多维数组等
1. 删除数组尾部元素 一个简单方法就是改变数组的length值: const arr = [11, 22, 33, 44, 55, 66]; arr.length = 3; console.log( ...
- TRUNCATE TABLE 与 DELETE (转)
TRUNCATE TABLE 删除表中的所有行,而不记录单个行删除操作.TRUNCATE TABLE 与没有 WHERE 子句的 DELETE 语句类似:但是,TRUNCATE TABLE 速度更快, ...
- skeljs框架关键点使用
global 全局 style.css containers: 1400px;容器宽度 xlarge 超大屏(media: max-width:1680px) style-xlarge.cs ...
- iOS捷径(Workflow 2.0)拓展
前言 iOS12 捷径(Workflow 2.0)入门 iOS12 捷径(Workflow 2.0)进阶 iOS12捷径(Workflow 2.0)实例大全 注:本文主要介绍如何获取URL Schem ...
- npm run dev报错--Error: Cannot find module 'yargs-parser'
Error: Cannot find module 'yargs-parser' ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...
- oracle 代码块
oracle 的代码块模板 declare --声明变量 begin --执行业务逻辑 exception --异常处理 end; --结束 注意:代码块每个sql语句结束都要加冒号 eg: --pl ...
- web.xml 加载顺序
参考网址: 上下文对象>监听>过滤器>servlet 1.先加载上下文对象 <!-- 初始化Spring classpath*:spring/applicationContex ...
- 文档兼容性定义,使ie按指定的版本解析
作为开发人员,特别是作为Web的前端开发人员 ,最悲催的莫过于要不断的,不断的去调试各种浏览器的显示效果,而这其中最让人头痛的莫过于MS下的IE系列浏览器,在IE系列中的调试我们将会发现没有一个是好伺 ...