Alice and Bob
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 20, Accepted users: 10
Problem 11499 : No special judgement
Problem description
Alice and Bob are interested in playing games. One day, they invent a game which has rules below:

  1. Firstly, Alice and Bob choose some random positive integers, and here we describe them as n,d1,d2,..,dm.
  2. Then they begin to write numbers alternately. At the first step, Alice has to write a “0”, here we let S1=0; Then, at the second step, Bob has to write a number S2 which satisfies the condition that S2=S1+dk and S2≤n, 1≤k≤m; From the third step, the person who has to write a number in this step must write a number Si which satisfies the condition that Si=Si-1+dk or Si= Si-1-dk , and Si-2 < Si ≤n, 1≤k≤m, i≥3 at the same time.
  3. The person who can’t write a legal number at his own step firstly lose the game.

Here’s the question, please tell me who will win the game if both Alice and Bob play the game optimally.

Input
At the beginning, an integer T indicating the total number of test
cases.
Every test case begins with two integers n and m, which are described
before. And on the next line are m positive integers
d1,d2,..,dm.
T≤100

1≤n≤10^6

1≤m≤100

1≤dk≤10^6,1≤k≤m

Output
For every test case, print “Case #k: ” firstly, where k indicates the
index of the test case and begins from 1. Then if Alice will win the game, print
“Alice”, otherwise “Bob”.

Sample Input
2
7 1
3
7 2
2 6
Sample Output
Case #1: Alice
Case #2: Bob

ps:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11499&courseid=136

【博弈:】

今天终于用到你了!

题意:Alice 和 Bob又玩游戏了,这次是这样的,看谁先超过给定的数,超过的人就输了;首先Alice

先输入s1=0;(相当于Bob优先)然后假设第 i 次的数字是 S[i] ,那么第 i+1 次的数字 S[i+1]= S[i]+d[k]或者 S[i]-d[k],条件是 S[i+1]<= n && S[i-1]<S[i+1]。比赛的时候没有“或者 S[i]-d[k]”这句话,不过这也没关系。

思路:我当时是这么想的,如果我来选,那么我肯定选最小的啊,这样离n才远,所以就选出dk里面的最小的,然后看看n/min(dk)是奇数呢还是偶数,如果是奇数Bob就win,偶数Alice就win;

加了红色的那句呢,也可以这么理解,如果我没错加min(dk),那么为了满足S[i-1]<S[i+1]那么后面的人只能加上数而不能剪数,那么又回到了上面的问题上;(ps:不能让对手减数就是要S[i]<S[i+1]这样才有赢得机会。)

#include<stdio.h>
int main()
{
int T,n,m,ans,tp,Case;
scanf("%d",&T);
for(Case=;Case<=T;Case++)
{
scanf("%d%d",&n,&m);
int min=;
for(int i=;i<m;i++)
{
scanf("%d",&ans);
if(ans<min)
min=ans;
}
tp=(n/min)%;
printf("Case #%d: ",Case);
if(tp==)
printf("Alice\n");
else
printf("Bob\n");
}
return ;
}

再不理解就想想那么直接想最后一步,什么时候就结束呢?自然是s(i)+min > n 时就输了

so。。你懂了。

再不懂的话。。。。

只能恕我能力低微,,,解释不清楚了。

Alice and Bob(博弈)的更多相关文章

  1. ZOJ 3529 A Game Between Alice and Bob 博弈好题

    A Game Between Alice and Bob Time Limit: 5 Seconds      Memory Limit: 262144 KB Alice and Bob play t ...

  2. UVaLive 5760 Alice and Bob (博弈 + 记忆化搜索)

    题意:有 n 堆石子,有两种操作,一种是从一堆中拿走一个,另一种是把两堆合并起来,Alice 先拿,谁不能拿了谁输,问谁胜. 析:某些堆石子数量为 1 是特殊,石子数量大于 1 个的都合并起来,再拿, ...

  3. HDU 4111 Alice and Bob (博弈+记忆化搜索)

    题意:给定 n 堆石头,然后有两种操作,一种是把从任意一堆拿走一个,另一种是把一个石子放到另一堆上. 析:整体看,这个题真是不好做,dp[a][b] 表示有 a 堆1个石子,b个操作,操作是指把其他的 ...

  4. ACdream 1112 Alice and Bob (博弈&amp;&amp;素数筛选优化)

    题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x ...

  5. BZOJ 3895 3895: 取石子 / Luogu SP9934 ALICE - Alice and Bob (博弈 记忆化搜索)

    转自PoPoQQQ大佬博客 题目大意:给定n堆石子,两人轮流操作,每个人可以合并两堆石子或拿走一个石子,不能操作者输,问是否先手必胜 直接想很难搞,我们不妨来考虑一个特殊情况 假设每堆石子的数量都&g ...

  6. Foj 2296 Alice and Bob(博弈、搜索)

    Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...

  7. 博弈 HDOJ 4371 Alice and Bob

    题目传送门 题意:Alice和 Bob轮流写数字,假设第 i 次的数字是S[i] ,那么第 i+1 次的数字 S[i+1] = S[i] + d[k] 或 S[i] - d[k],条件是 S[i+1] ...

  8. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  9. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. Effective C++笔记:继承与面向对象设计

    关于OOP 博客地址:http://www.cnblogs.com/ronny 转载请注明出处! 1,继承可以是单一继承或多重继承,每一个继承连接可以是public.protected或private ...

  2. 通过修改EIP寄存器实现远程注入

    功能:通过修改EIP寄存器实现32位程序的DLL注入(如果是64位,记得自己对应修改汇编代码部分) 原理: 挂起目标进程,停止目标进程EIP的变换,在目标进程开启空间,然后把相关的指令机器码和数据拷贝 ...

  3. Tomcat在Linux下的安装

    按部就班的把 tomcat 上传到 Linux 我创建了一个文件夹用作存放解压文件 ( tomcat只要解压就可以使用 ) 解压  :  tar -xvf apache-tomcat-7.0.52.t ...

  4. web开发常用网络优化

    优化方法: 1.合并资源文件,减少HTTP请求 2.压缩资源文件减少请求大小 3.利用缓存机制,尽可能使用缓存减少请求 如何做前端路由 html5 api中的history能够让我们控制url跳转之后 ...

  5. Vim使用Vundle安装代码补全插件(YouCompleteMe)

    安装 Vundle 它的使用方法很简单,安装一个插件只需要在 ~/.vimrc 按照规则中添加 Plugin 的名称,某些需要添加路径,之后在 Vim 中使用:PluginInstall既可以自动化安 ...

  6. Ubuntu 14.04TLS Nginx搭建静态文件服务器

    Nginx搭建静态文件服务器 [官方教程]https://www.nginx.com/resources/admin-guide/serving-static-content/ 打开Nginx的配置文 ...

  7. [LeetCode] 206. Reverse Linked List_Easy tag: Linked List

    Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...

  8. How To Scan QRCode For UWP (2)

    这篇随笔主要介绍照相预览功能,重要使用的是MediaCapture对象,MediaCapture对象还可以用来处理录音和录制视频,本文只讨论照相功能. 1:查找摄像头 后置摄像头优先,找不到后置摄像头 ...

  9. Hive中的Row_Number()使用

    语法:row_number() over (partition by 字段a order by 计算项b desc ) rank --这里rank是别名 partition by:类似hive的建表, ...

  10. (转)使用 db2pd 命令进行监视和故障诊断

    原文:https://www.ibm.com/support/knowledgecenter/zh/SSEPGG_9.7.0/com.ibm.db2.luw.admin.trb.doc/doc/c00 ...