zoukankan      html  css  js  c++  java
  • UVA 11859 Division Game

    白书的例题,做法是记好每个数的质因数的个数,然后就可以转化为简单的nim游戏。

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int maxn = 1010;
    int a[maxn][maxn];
    int prime[10010];
    int cnt[10010]; 
    void init() {
        prime[0] = prime[1] = 1;
        for(int i = 2; i < 10010; i++) {
            cnt[i] = 0;
            if(prime[i] == 0) {
                for(int j = 2 * i; j < 10010; j += i) 
                    prime[j] = 1;
            }
        }
        for(int i = 2; i <= 10010; i++) {
            int tmp = i;
            while(tmp) {
                if(prime[tmp])
                    for(int j = 2; j * j <= tmp; j++) {
                        if(tmp % j == 0 && !prime[j]) {
                            cnt[i]++;
                            tmp /= j;
                        }
                    }
                else {
                    if(tmp != 1) cnt[i]++;
                    break;
                }
            }
        }
    }
    int main() {
        int t;
        init();
        scanf("%d", &t);
        int val = 0;
        while(t--) {
            int n, m;
            scanf("%d %d", &n, &m);
            for(int i = 1; i <= n; i++) 
                for(int j = 1; j <= m; j++)
                    scanf("%d", &a[i][j]);
            int cnt2[maxn]; memset(cnt2, 0, sizeof(cnt2));
            for(int i = 1; i <= n; i++) {
                for(int j = 1; j <= m; j++) {
                    cnt2[i] += cnt[a[i][j]];
                }
            }
            int ans = 0;
            for(int i = 1; i <= n; i++) ans ^= cnt2[i];
            /*for(int i = 1; i <= n; i++) {
                printf("%d ", cnt2[i]);
            }puts("");*/
            printf("Case #%d: ", ++val);
            if(ans) puts("YES");
            else puts("NO");
        }
    }//
  • 相关阅读:
    array_count_values源码
    php 编译安装记录
    mysql 安装的过程做个记录
    初识highcharts 库
    php 不重新编译增加新扩展的方法
    备考PMP
    Beyond Compare4破解--写reg脚本删除注册表
    SourceTree 跳过登录
    正则 (?=exp)
    springmvc--处理器的返回参数
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5690548.html
Copyright © 2011-2022 走看看