zoukankan      html  css  js  c++  java
  • bjfu1164 Parity Game

    简单规律题。首先想到的是,若01串中1有n个,则可以通过操作,使串中1的个数变为n-1、n-2……1、0个;第2个想到的是,如果n为奇数,可以通过操作,使串中1的个数最多变为n+1,而若n为偶数,则无法增加1的个数;第3个想到的是,两个串如果1的个数相同,则一定可以相互转换(这个有点难想,我感觉是对的,而且写程序验证了)。想到这里,题目就非常简单了。

    /*
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 1010;
    char str1[MAXN], str2[MAXN];
    
    int main() {
        while(scanf("%s%s", str1, str2) == 2) {
            int len1 = strlen(str1);
            int len2 = strlen(str2);
            int num1 = count(str1, str1 + len1, '1');
            int num2 = count(str2, str2 + len2, '1');
            if(num1 % 2 == 1) {
                num1++;
            }
            if(num1 >= num2) {
                printf("YES
    ");
            } else {
                printf("NO
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    用windows脚本实现文件下载
    pku1325 Machine Schedule
    中位数
    pku1468 Rectangles
    最小密度路径
    合并序列
    PowerDesigner(5)转载
    责任链模式
    PowerDesigner(3)转载
    解释器模式
  • 原文地址:https://www.cnblogs.com/moonbay/p/3621789.html
Copyright © 2011-2022 走看看