Alice and Bob(博弈)
| 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:
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 |
| Sample Output |
Case #1: Alice |
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(博弈)的更多相关文章
- 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 ...
- UVaLive 5760 Alice and Bob (博弈 + 记忆化搜索)
题意:有 n 堆石子,有两种操作,一种是从一堆中拿走一个,另一种是把两堆合并起来,Alice 先拿,谁不能拿了谁输,问谁胜. 析:某些堆石子数量为 1 是特殊,石子数量大于 1 个的都合并起来,再拿, ...
- HDU 4111 Alice and Bob (博弈+记忆化搜索)
题意:给定 n 堆石头,然后有两种操作,一种是把从任意一堆拿走一个,另一种是把一个石子放到另一堆上. 析:整体看,这个题真是不好做,dp[a][b] 表示有 a 堆1个石子,b个操作,操作是指把其他的 ...
- ACdream 1112 Alice and Bob (博弈&&素数筛选优化)
题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x ...
- BZOJ 3895 3895: 取石子 / Luogu SP9934 ALICE - Alice and Bob (博弈 记忆化搜索)
转自PoPoQQQ大佬博客 题目大意:给定n堆石子,两人轮流操作,每个人可以合并两堆石子或拿走一个石子,不能操作者输,问是否先手必胜 直接想很难搞,我们不妨来考虑一个特殊情况 假设每堆石子的数量都&g ...
- Foj 2296 Alice and Bob(博弈、搜索)
Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...
- 博弈 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] ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- BZOJ 2200--[Usaco2011 Jan]道路和航线(最短路&拓扑排序)
2200: [Usaco2011 Jan]道路和航线 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1128 Solved: 414[Submit] ...
- [NOIP2018]赛道修建(二分+multiset)
考场上打了一个 \(vector\) 解法,因为我当时不会 \(multiset\) 好吧,我来讲一讲今年的 \(tgD1T3\) 首先,这题 \(55\) 分是不难想的 1. \(b_i=a_i+1 ...
- [Umbraco] document type里的父节点与子节点的设置
虽然我们不能像做数据库设计那样建立主外键关系.但我们建立xml里父子关系,父子关系其实是指是否允许在一个页面(如频道,分类,栏目等)下创建子页面,这就相当于建立站点的树状结构,对于筛选数据会有很大的作 ...
- socket练习:FTP
FTP 练习收获: 1,类型转换 2,进度条实现: 3,print 输出不换行的方法: print输出 不换行的方法: 方法一: import sys sys.stdout.write(" ...
- 剑指offer二十之包含min函数的栈
一.题目 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. 二.思路 用一个栈dataStack保存数据,用另外一个栈minStack保存依次入栈最小的数.每次元素存入minSt ...
- spring jpa : 多条件查询
https://www.cnblogs.com/Donnnnnn/p/6277872.html 方式一: 第一步:EmpAccNumService package com.payease.scford ...
- Maven启用代理服务器访问
0.什么叫代理服务器? 代理服务器英文全称是(Proxy Server),其功能就是代理网络用户去取得网络信息.形象的说:它是网络信息的中转站. 代理服务器就好象一个大的Cache,这样就能显著提高浏 ...
- php -- 数学函数
----- 016-math.php ----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...
- mysql笔记-索引
什么是聚簇索引 聚簇索引:索引的叶节点就是数据节点(索引值).而非聚簇索引的叶节点仍然是索引节点(告诉你怎么在表中查找这一记录),只不过有一个指针指向对应的数据块. Innodb和MyIsam区别 转 ...
- TCP保活的必要性
TCP的长连接理论上只要连接建立后,就会一直保持着.但有时有一些防火墙之类的软件会自动检查主机的网络连接状况,比如说如果发现某个连接在几分钟之内都没有数据通讯,则会关闭这个连接.有时客户端与服务器需要 ...