ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)
来源:互联网 发布:达内培训 数据大 编辑:程序博客网 时间:2024/05/29 03:46
Alice and Bob play the following game. A series of numbers is written on the blackboard. Alice and Bob take turns choosing one of the numbers, and replace it with one of its positive factor but not itself. The one who makes the product of all numbers become 1 wins. You can assume Alice and Bob are intelligent enough and Alice take the first turn. The problem comes, who is the winner and which number is Alice's first choice if she wins?
Input
This problem contains multiple test cases. The first line of each case contains only one numberN (1<= N <= 100000) representing there are N numbers on the blackboard. The second line containsN integer numbers specifying the N numbers written on the blackboard. All the numbers are positive and less than or equal to 5000000.
Output
Print exactly one line for each test case. The line begins with "Test #c: ", wherec indicates the case number. Then print the name of the winner. If Alice wins, a number indicating her first choice is acquired, print its index after her name, separated by a space. If more than one number can be her first choice, make the index minimal.
Sample Input
45 7 9 12441503 15991 72 16057
Sample Output
Test #1: Alice 1Test #2: Bob
题目大意:黑板上有n个数,每一次操作可以将其中一个数变成除它本身之外的因数。Alice先开始,轮流操作,最后使黑板上的数字都为1的人获胜。如果是Alice获胜还需要输出她第一步变第几个数
每次只能操作一个数很容易想到nim游戏,对于这道题来说每一堆就是每个数字的所有素因子的个数之和
转换成普通的nim游戏之后就很容易了
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int num[5000100],p[5000100],a[5000100];int cs=0,cnt=0,n;void prime(){ for(int i=2;i<=5000000;i++){ if(!p[i]){ num[i]++; for(int j=i+i;j<=5000000;j+=i){ p[j]=1; int temp=j; int z=0; while(temp%i==0) { temp/=i; z++; } num[j]+=z; } } }}int main(){ memset(num,0,sizeof(num)); memset(p,0,sizeof(p)); prime(); while(~scanf("%d",&n)){ int temp=0; for(int i=0;i<n;i++){ scanf("%d",&a[i]); //cout<<"num="<<num[a[i]]<<" "; temp^=num[a[i]]; } printf("Test #%d: ",++cs); if(temp==0) printf("Bob\n"); else{ for(int i=0;i<n;i++){ int ans=temp^num[a[i]]; if(ans<=num[a[i]]){ printf("Alice %d\n",i+1); break; } } } } return 0;}
- ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)
- ZOJ 3529 A Game Between Alice and Bob(博弈)
- ZOJ-#3529 A Game Between Alice and Bob(Nim和+素数因子)
- ZOJ 3529 A Game Between Alice and Bob (数论+SG博弈)
- ZOJ 3529 A Game Between Alice and Bob 博弈好题
- Zoj 3529 A Game Between Alice and Bob (数学_博弈)
- Zoj 3529 A Game Between Alice and Bob
- A Game Between Alice and Bob(zoj 3529)
- ZOJ 3529 A Game Between Alice and Bob
- ZOJ 3529 A Game Between Alice and Bob(博弈论-sg函数)
- zoj3529 A Game Between Alice and Bob 博弈
- [博弈论]A Game Between Alice and Bob
- zoj3529 A Game Between Alice and Bob
- A Game Between Alice and Bob
- zoj3529 A Game Between Alice and Bob 质因子个数NIM
- ZOJ 3666 Alice and Bob(博弈)
- ZOJ 3666 Alice and Bob(博弈 sg 函数入门)
- ZOJ 3666 Alice and Bob 基础博弈
- 【Python】文件操作,read(), readline(), readlines()
- iOS—动画效果和实现
- Oracle方案、权限、角色概述
- openfire IM架构
- android倒计时类CountDownTimer
- ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)
- Myeclipse中搭建Android开发环境
- openfire集群解决方案
- 关于科学的文章?一只肉鸡的科学一生?
- Android gallery实现图片的左右循环旋转源码分享
- 连接手机,获得手机写权限
- 把自己当成别人、把别人当成自己、把别人当成别人、把自己当成自己
- Wav头文件格式讲解
- 第一次装好mysql后要设置密码