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 ...
随机推荐
- P4323 [JSOI2016]独特的树叶(树哈希)
传送门 树哈希?->这里 反正大概就是乱搞--的吧-- //minamoto #include<bits/stdc++.h> #define R register #define l ...
- [App Store Connect帮助]八、维护您的 App(4.3)回复顾客评论(iOS、macOS 或 watchOS)
您可以公开回复顾客评论,但在您的 App Store 产品页上每条评论仅会显示一条回复.您可以回复评论.编辑回复,以及删除回复. 在回复和编辑显示在 App Store 上之前(可能需要至多 24 小 ...
- Qt事件系统之二:鼠标事件和滚轮事件
在Qt中,事件作为一个对象,继承自 QEvent 类,常见的有键盘事件 QKeyEvent.鼠标事件 QMouseEvent 和定时器事件 QTimerEvent 等,与 QEvent 类的继承关系图 ...
- BZOJ2333 棘手的操作
Description 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点 A1 x ...
- YUM报错及解决办法
[root@xuegod60 ~]# yum clean all Loaded plugins: product-id, refresh-packagekit, security, subscript ...
- 针对谷歌默认最小字体12px的正确解决方案
利用css3的缩放,其最终大小就是:12px * 0.9(缩放比例) = 10.8px; 居然行得通.但回头一想,这么写的话,IE7 IE8会不会不兼容,还是12px呢?不出所料,果然不兼容.此时,又 ...
- webapp开发学习--Ionic+Cordova 环境搭建
我们看 Ionic 能给我们提供什么? 一个样式库,你可以使用它来装饰你的HTML网页 ,看起来 想 移动程序的界面,什么header .content.footer.grid.list.这貌似没什么 ...
- AJPFX总结final、finally、finallize的区别
final.finally.finallize有何区别? final表示一个修饰符,如果用它来修饰一个类,则该类是不能继承的:如果用它来修饰一个变量,则该变量一旦赋值之后就不能再修改:如果用它来 ...
- EditText自动弹出软键盘
editText.requestFocus() editText.isFocusable = true editText.isFocusableInTouchMode = true val timer ...
- Android EditText 输入金额(小数点后两位)
EditText edit = new EditText(context); InputType.TYPE_NUMBER_FLAG_DECIMAL //小数点型 InputType.TYPE_CLAS ...