poj 1063 Flip and Shift 规律题

  当总数量 N 为奇数的时候, 因为N为奇数,N+1变成1,同样为奇数. 则意味着奇偶位置可以相互转换.

  但是当N为偶数的时候,因为N为偶数,N+1变成1,转换成了奇数. 奇数位置,和偶数位置不相关.

  因为我们的置换规则是 奇数位置和奇数位置对换, 偶数位置和偶数位置对换. 

  那么当N为奇数时,可以转换成任意形态.  但是当N为偶数时,仅仅当奇数位置上的黑点数量与偶数上的黑点数量相差小于等于1

的时候,才可转换成符合条件的情况.

解题代码

View Code
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int n, odd, even, T;
    scanf("%d", &T);
    while( T-- )
    {
        scanf("%d",&n);
        odd = even = 0;
        int x;    
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &x);
            if( x ){
                if( i&1 ) odd++;
                else    even++;
            } 
        }
        if( n&1 ) puts("YES");
        else
        {
            if( abs(odd-even) < 2 ) puts("YES");
            else    puts("NO");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/yefeng1627/p/2851549.html