博弈 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] <= n && S[i-1]<S[i+1]
分析:设d[]最小的数字为mn,除此之外设为d,第一次A写了0,第二次B如果写了d,那么A可以写d - mn,确保自己有数直到胜利;如果B第一次写了mn,那么以后的数都只能加mn直到>n,这个很好判断谁胜利。
收获:博弈题想到了就简单了
代码:
#include <cstdio>
#include <algorithm>
using namespace std; const int M = 1e2 + 10;
int a[M]; int main(void) {
int T, cas = 0;
int n, m;
scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
for (int i=1; i<=m; ++i) scanf ("%d", &a[i]);
printf ("Case #%d: ", ++cas);
sort (a+1, a+1+m);
if ((n / a[1]) & 1) puts ("Bob");
else puts ("Alice");
} return 0;
}
博弈 HDOJ 4371 Alice and Bob的更多相关文章
- Alice and Bob(博弈)
Alice and Bob Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...
- Foj 2296 Alice and Bob(博弈、搜索)
Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 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 ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- Alice and Bob(不断补充)
我之前做过一些博弈的题目,以为博弈都是DP,结果被坑了很多次,其实博弈有很多种,在此,把我见过的类型都搬上来. 1,HDU3951(找规律) 题意:把n枚硬币围成一个圆,让Alice和Bob两个人分别 ...
- hdu4111 Alice and Bob
Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- XTU OJ 1209 Alice and Bob 2014(嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛)
Problem Description The famous "Alice and Bob" are playing a game again. So now comes the ...
随机推荐
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- Visual Studio VS如何切换代码自动换行
工具-选项-文本编辑器-自动换行
- (void __user *)arg 中__user的作用
__user宏简单告诉编译器(通过 noderef)不应该解除这个指针的引用(因为在当前地址空间中它是没有意义的). (void __user *)arg 指的是arg值是一个用户空间的地址,不能直接 ...
- Linux bash介绍与使用
Linux————bash的简单使用 对于一个操作系统来说,shell相当于内核kernel外的一层外壳,作为用户接口.一般来说,操作系统的接口分为两类:CLI:command line interf ...
- Windows Server 2012 R2 安装.NET Framework 3.5报错
简单记录一下,Windows Server 2012 R2 安装.NET Framework 3.5报错,下面是解决方法 载入ISO文件Windows Server 2012 R2,而且在安装的过程中 ...
- elasticsearch_初始篇
一.elasticsearch简单介绍 Elasticsearch 是一个基于Lucene的分布式.可扩展.近实时的搜索与数据分析引擎. 它能从项目一开始就赋予你的数据以搜索.分析和探索的能力. 实时 ...
- python 2.*和3.*的变化
1.urllib2是python自带的模块,在python3.x中被改为urllib.request,如 <span style="font-size:12px;">u ...
- 【扩展知识2】函数strlen()和非函数sizeof的使用
[扩展知识2]函数strlen()和非函数sizeof的使用 [扩展文件夹] strlen函数 sizeof ( 1 )函数strlen() 原型:size_tstrlen ( const char ...
- <s:property>的用法(jsp获取action中的值或者方法)
1,访问Action值栈中的普通属性: <s:property value="attrName"/> 2,访问Action值栈中的对象属性(要有get set方法) ...
- fastjson将json字符串中时间戳转化为日期
开发中,调用接口,往往会返回一个json字符串.对于json中的时间戳应该如何转为日期对象呢? 定义一个DateValueFilter类,这个类实现了fastjson中ValueFilter接口.其作 ...