BestCoder Round #67 (div.2) 1001——N bulbs

探讨了灯泡状态序列中开关操作与路径选择的关系,通过判断灯泡总数与状态为1的数量是否同奇同偶,来决定是否能实现所有灯泡关闭的目标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:给定一个长度为n的灯泡的状态序列,经过每个灯泡时,都要开关一下(开变关,关变开),问能否在回到终点的条件下关掉所有的灯。


思路:没出现一个为1的灯,都需要走奇数步来关掉它,而灯的总数为奇数的时候才能走奇数步,偶数同理。那么总数和1的个数同奇同偶时为YES。


code:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define ft(i,s,t) for (int i=s;i<=t;i++)
#define cls(a,c) memset(a,c,sizeof(a))
typedef long long ll;
const int N=1000006;
const int M=105;


int main()
{
    int T;
    scanf("%d",&T);
    while (T--){
        int s=0,t,n;
        scanf("%d",&n);
        ft(i,1,n) {
            scanf("%d",&t);
            if (t==1) s++;
        }
        if (n%2&&s%2) puts("YES");
        else if (n%2==0&&s%2==0) puts("YES");
        else puts("NO");
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值