ZOJ3529_A Game Between Alice and Bob
题目的意思是给你若干个数字,两个游戏者轮流操作,每次可以将该数变为一个小于当前的一个约数,无法操作的游戏者fail。
和其他的博弈题目大同小异吧。
不同点有两个,逐一分析吧。
一、每次改变一个数只能改变为小于当前数的约数,所以相对来说Sg函数值得求法有点不同哦。自己打个表就可以发现这个题目的Sg函数值是该数的除了1以为的约数的个数。这样我们可以用一点数论的知识把Sg函数值搞定了。
二、题目还要对于必胜态,输出改变的标号最小的数。就是对于每一个数,异或判断是否可行就可以了。
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 5000005
using namespace std; int sg[maxn];
int a[],n,m,ans; void init_sg()
{
memset(sg,,sizeof sg);
for (int i=; i<maxn; i++)
{
if (sg[i]) continue;
for (int k=,j; maxn/k>=i; )
for (k*=i,j=k; j<maxn; j+=k) sg[j]++;
}
} int main()
{
int cas=;
init_sg();
while (scanf("%d",&n)!=EOF)
{
ans=m=;
for (int i=; i<=n; i++) scanf("%d",&a[i]),m^=sg[a[i]];
for (int i=; i<=n; i++)
{
if ((m^sg[a[i]])<sg[a[i]])
{
ans=i;
break;
}
}
if (m) printf("Test #%d: Alice %d\n",++cas,ans);
else printf("Test #%d: Bob\n",++cas);
}
return ;
}
ZOJ3529_A Game Between Alice and Bob的更多相关文章
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- SDUT 2608:Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
随机推荐
- Oracle下建立dblink时的权限问题
如果用普通用户,如果没授权,是无法建立dblink的: [oracle@oracle000 ~]$ sqlplus gao/gao lines) SQL Production :: Copyright ...
- KVM虚拟化的安装
kvm介绍 一.KVM的历史 Kvm在2007年2月正式合并Linux2.6.20核心中,成为内核源代码的一部分.2008年9月4日,RedHat公司收购了Qumranet,开始在RHEL中用kvm取 ...
- Spring学习(十)-----Spring依赖检查
在Spring中,可以使用依赖检查功能,以确保所要求的属性可设置或者注入. 依赖检查模式 4个依赖检查支持的模式: none – 没有依赖检查,这是默认的模式. simple – 如果基本类型(int ...
- Git生成多个ssh key
在实际的工作中, 有可能需要连接多个远程仓库, 例如我想连接私有仓库.GitLab官网.GitHub官网, 那么同一台电脑就要生成多个ssh key: ssh-keygen -t rsa -C &qu ...
- 从零开始的Python学习Episode 11——装饰器
装饰器 装饰器是用来处理其他函数的函数,主要作用是在不修改原有函数的情况下添加新的功能,装饰器的返回值也是一个函数对象. 简单的装饰器 import time def show_time(f): de ...
- 【Python进阶】用 Python 统计字数
问题描述: 用 Python 实现函数 count_words(),该函数输入字符串 s 和数字 n,返回 s 中 n 个出现频率最高的单词.返回值是一个元组列表,包含出现次数最高的 n 个单词及其次 ...
- ViewPort <meta>标记
ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...
- python实现中文验证码识别方法(亲测通过)
验证码截图如下: # coding:utf-8from PIL import Image,ImageEnhanceimport pytesseract#上面都是导包,只需要下面这一行就能实现图片文字识 ...
- Python中的构造函数
Python中的构造函数是__init__函数.在Python中,子类如果定义了构造函数,而没有调用父类的,那么Python不会自动调用,也就是说父类的构造函数不会执行. 比如有test.py的mod ...
- 《C》变量
变量的存储方式和生存周期