Codeforces 850C E. Arpa and a game with Mojtaba

对每个数统计其素数因子各次方数的数,然后通过y = (x>>i) | (x&((1<<(i-1))-1)) 模拟delete x and add  to the list 操作,用grund函数将每个因子的情况映射为NIM问题中一个堆的情况,再按NIM问题的求解方法求解

参考链接 https://www.topcoder.com/community/data-science/data-science-tutorials/algorithm-games/

#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
unordered_map<int,int> ttmp;
int n,tmp,y;
int grund(int x){
    if(ttmp.count(x)) return ttmp[x];
    unordered_set<int> s;
    for(int i = 1;i<=30;i++){
        y = (x>>i) | (x&((1<<(i-1))-1));
        if(y!=x) s.insert(grund(y));
    }

    int ans = 0;
    while(s.count(ans)) ans++;
    return ttmp[x] = ans;
}
int main(){
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>tmp;
        for(int j = 2;j*j<=tmp;j++){
            if(tmp%j == 0){
                int cnt = 0;
                while(tmp%j == 0){
                    tmp/=j;
                    cnt++;
                }
                mp[j] |= (1<<cnt-1);
            }
        }
        if(tmp>1) mp[tmp] |= 1;
    }
    int ans = 0;
    ttmp[0] = 0;
    for(auto t : mp){
        ans^=grund(t.second);
    }
    cout<<(ans?"Mojtaba":"Arpa")<<endl;
    return 0;
}
时间: 2024-07-29 05:25:46

Codeforces 850C E. Arpa and a game with Mojtaba的相关文章

[Codeforces 850C]Arpa and a game with Mojtaba

Description 题库链接 两个人 Van♂ 游戏.给出 \(n\) 个正整数 \(a_i\) .两人轮流操作,每次选出一个素数 \(p\) 和一个幂数 \(k\) ,选择的前提为该 \(n\) 个数中有 \(p^k\) 的倍数.接着将所有的 \(p^k\) 的倍数除以 \(p^k\) .变成新的序列,继续操作.不能操作者为败,问先手是否必胜. \(1\leq 100\leq n,1\leq a_i\leq 10^9\) Solution 首先显然的是不同的素数间是不会互相影响的.显然这个

Codeforces 741 D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths

D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 思路: 树上启发式合并 从根节点出发到每个位置的每个字符的奇偶性记为每个位置的状态,每次统计一下每个状态的最大深度 为了保证链经过当前节点u,我们先计算每个子树的答案,再更新子树状态对深度的贡献. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bit

[CodeForces850C]Arpa and a game with Mojtaba

题目大意: 给你一个包含n个数的数列,两个人轮流对数列进行如下操作: 选择一个质数p和一个正整数k,将数列中所有能被p^k整除的数除以p^k. 最后不能操作者负. 问先手是否有必胜策略. 思路: 显然,结果不直接与数列中数的值有关,而与数列中每个数的质因数及其次数有关,因此我们可以将每个质因数分开考虑. 枚举数列中出现的每一个质因数p,对数列中的数除去p^k就相当于将p对应的次数减去k. 如果不同的数对于同一个质因数p,对应的次数相同,那么无论除去p的几次,对于这两个数的影响都是一样的. 那么我

Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses CodeForces - 742D

Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship grou

http://codeforces.com/contest/741/problem/B B. Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses

题意: 给出上限体重W 然后还给出每个人的体重wi 和 魅力值 bi 互为伙伴的对(xi, yi) 可以凑成group 思路: 并查集找出所有的group 暴力背包 对于每一个group 要选出这一组内选一个人时的最优结果, 如果所有人的体重和小于等于W,还得考虑选所有人的情况 #include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include &l

Codeforces 741B Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses

[题目链接] http://codeforces.com/problemset/problem/741/B [题目大意] 给出一张图,所有连通块构成分组,每个点有价值和代价, 要么选择整个连通块,要么只能在连通块中选择一个,或者不选,为最大价值 [题解] 首先我们用并查集求出连通块,然后对连通块进行分组背包即可. [代码] #include <cstdio> #include <vector> #include <algorithm> #include <cstr

codeforces 742D Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses ——(01背包变形)

题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <vector> 5 using namespace std; 6 const int N = 1000 + 5;

codeforces 851D Arpa and a list of numbers

目录 codeforces 851D Arpa and a list of numbers 题意 题解 Code codeforces 851D Arpa and a list of numbers 题目传送门 题意 给出\(n\)个数,有两种操作: 1.将一个数从数列中删除,代价为\(x\). 2.将一个数加1,代价为\(y\). 询问最少花费多少的代价能够使数列中所有数的\(Gcd\)不为1. \((1 \leq n \leq 5 \cdot 10^5 , 1 \leq x,y \leq 1

【Codeforces 851D Arpa and a list of numbers】

Arpa的数列要根据GCD变成好数列. ·英文题,述大意:      给出一个长度为n(n<=5000000)的序列,其中的元素a[i]<=106,然后输入两个数x,y(x,y<=109)现在有两种操作:①支付x的代价删除一个数.②支付y的代价将一个数加1.题目要求支付最少的代价,使得原序列所有元素的GCD不为1. ·分析:      GCD不为1?那么就是说每个数至少有一个共同的非1因子.使所有数拥有同一个因子一定比使它们拥有两个相同因子容易,所以题目其实要求我们完成这个任务:对于某个