解题报告:Codeforces Round #432 (Div. 2) E.Arpa and a game with Mojtaba (博弈)
2017-09-05 19:27
561 查看
题目链接
题意:
有n个数,每次可以选择一个素数p,和一个整数k
要求n个数中至少存在一个数x满足:( p^k | x )
然后将n个数中所有p^k能整除的数除以p^k
两个人轮流进行操作,无法操作的一方输,问初始局势的胜负态
思路:
很明显不同素数之间的局势相互独立,O(n*sqrt(maxa))处理出后可以状压至二进制
那么答案就是各个素数的局势的sg异或
但是发现素数2的二进制局势可以达到2^30次方,无法预处理出来
那么可以先预处理出2^20内的局势,对于大于这个局势的,用离散化的记忆化搜索求解即可
代码:
题意:
有n个数,每次可以选择一个素数p,和一个整数k
要求n个数中至少存在一个数x满足:( p^k | x )
然后将n个数中所有p^k能整除的数除以p^k
两个人轮流进行操作,无法操作的一方输,问初始局势的胜负态
思路:
很明显不同素数之间的局势相互独立,O(n*sqrt(maxa))处理出后可以状压至二进制
那么答案就是各个素数的局势的sg异或
但是发现素数2的二进制局势可以达到2^30次方,无法预处理出来
那么可以先预处理出2^20内的局势,对于大于这个局势的,用离散化的记忆化搜索求解即可
代码:
#include<bits/stdc++.h> const int N = 1<<20,L=32e3; #define se second using namespace std; vector<int>pr; int sg ; bool Np[L]; map<int,int>M,SG; inline int work(int x){ if(x<N&&sg[x]>=0)return sg[x]; else if(x>=N&&SG.find(x)!=SG.end())return SG[x]; bool num[35]={0}; int res = 0; for(int i=1,j=1;j<=x;++i,j<<=1){ int t = (x>>i)|(x&(j-1)); num[work(t)]=1; }while(num[res])++res; return x<N?sg[x]=res:SG[x]=res; } void init(){ memset(sg,-1,sizeof(sg)); for(int i=1;i<N;++i)sg[i] = work(i); for(int i=2;i<L;++i){ if(!Np[i])pr.emplace_back(i); for(int j=0,k=pr[0]*i;k<L;k=pr[++j]*i){ Np[k]=true; if(i%pr[j]==0)break; } } } void oper(int x){//printf("in"); int m = sqrt(x+0.5); for(int i=0;pr[i]<=m&&x>1;++i){ if(x%pr[i]==0){ int t = 1; while(x%pr[i]==0)t<<=1,x/=pr[i]; t>>=1; M[pr[i]]|=t; } }if(x>1)M[x]|=1; } int main() { init(); int n,x,ans=0; scanf("%d",&n); while(n--){ scanf("%d",&x); oper(x); }for(auto it:M){ ans ^= work(it.se); }printf("%s\n",ans?"Mojtaba":"Arpa"); return 0; }
相关文章推荐
- Codeforces Round #432 (Div. 2) (Codeforces 850C) E. Arpa and a game with Mojtaba 博弈+状态压缩
- 解题报告:Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers 暴力
- Codeforces Round #383 (Div. 1) Problem B.Arpa's weak amphitheater and Mehrdad's valuable Hoses 解题报告
- Codeforces Round #383 (Div. 1) Problem A. Arpa's loud Owf and Mehrdad's evil plan 解题报告
- Codeforces 851E-Arpa and a game with Mojtaba
- Codeforces Round #396 (Div. 2) E题Mahmoud and a xor trip(树状dp)解题报告
- 解题报告: Codeforces Round #305 (Div. 2) E.Mike and Foam (莫比乌斯反演)
- 解题报告:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations (DP)
- Codeforces Round #399 (Div. 1 + Div. 2, combined) D题Jon and Orbs(dp)解题报告
- (难)Codeforces Round #406 (Div. 2) C题Berzerk(有向图博弈)解题报告
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 解题报告
- Codeforces Round #297 (Div. 2) A - Vitaliy and Pie 解题报告
- Codeforces Round #365 (Div. 2) Problem D.Mishka and Interesting sum 解题报告
- 【Codeforces Round #432 (Div. 1) C】 Arpa and a game with Mojtaba
- Codeforces Round #297 (Div. 2) B. Pasha and String 解题报告
- 【解题报告】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- 解题报告:Codeforces Round #381 (Div. 1)B. Alyona and a tree
- codeforces 850C Arpa and a game with Mojtaba(博弈,bitmask)
- Codeforces Round #297 (Div. 2) C. Ilya and Sticks 解题报告
- 解题报告:HDU 4111 Alice and Bob 递推|博弈