• 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;
    }
  • 相关阅读:
    SVN日常使用
    zabbix安装
    shell日常脚本(centos6)
    mysql故障记录
    PHP商品秒杀功能实现思路分析
    Redis
    PHP 实现实时通信一般有两种方式
    FTP DNS SMTP POP3 HTTP HTTPS DHCP DNS SNMP Telnet 端口号
    TCP/UDP/HTTP的区别和联系
    TCP 和 UDP 的区别
  • 原文地址:https://www.cnblogs.com/Invisible-full-moon/p/7491447.html
Copyright © 2020-2023  润新知