CodeForces Round #180 (297A) - Parity Game

    题意说能否使a串等于b串...a串的转换操作为: 1>在末位加上奇偶校验位(偶数个1为0...奇数个为0)  2>去掉a的首位   ... 1,2操作可以多次进行...

    可见...若a的1为偶数个...末尾可以加任意多的0...如果a的1为奇数个..在a后加1后..a的1又变成偶数个了..若想能再在a的末尾加1...只能去掉a前面的一个1...

    所以...若a有k个1..可以通过在末尾生成 奇偶校验位0,1的方法构造出任意个1的个数<=k的串....但不要忽略一种情况..当k为奇数时可在末尾直接添加1..相等于有k+1个1...


Program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define ll long long 
#define oo 1000000001
#define MAXN 400005
using namespace std;    
char s1[1005],s2[1005];
int l1,l2;
bool doit()
{
       int i,x1,x2;
       x1=0;
       for (i=1;i<=l1;i++)
         if (s1[i]=='1') x1++;
       if (x1%2) x1++;
       x2=0;
       for (i=1;i<=l2;i++)
         if (s2[i]=='1') x2++;
       if (x1>=x2) return true;
       return false; 
}
int main()
{      
       int i,k=0;
       while (gets(s1+1))
       {
             gets(s2+1);
             l1=strlen(s1+1);
             l2=strlen(s2+1);  
             if (doit()) printf("YES\n"); 
               else printf("NO\n");
       }
       return 0;
}


你可能感兴趣的:(CodeForces Round #180 (297A) - Parity Game)