BestCoder Round #67 (div.2) 1001——N bulbs
生活随笔
收集整理的這篇文章主要介紹了
BestCoder Round #67 (div.2) 1001——N bulbs
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:給定一個(gè)長度為n的燈泡的狀態(tài)序列,經(jīng)過每個(gè)燈泡時(shí),都要開關(guān)一下(開變關(guān),關(guān)變開),問能否在回到終點(diǎn)的條件下關(guān)掉所有的燈。
思路:沒出現(xiàn)一個(gè)為1的燈,都需要走奇數(shù)步來關(guān)掉它,而燈的總數(shù)為奇數(shù)的時(shí)候才能走奇數(shù)步,偶數(shù)同理。那么總數(shù)和1的個(gè)數(shù)同奇同偶時(shí)為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");} }總結(jié)
以上是生活随笔為你收集整理的BestCoder Round #67 (div.2) 1001——N bulbs的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML富文本中,如何实现加粗按钮后,输
- 下一篇: uva 11995——I Can Gu