BestCoder Round #67 (div.2) 1001——N bulbs
生活随笔
收集整理的這篇文章主要介紹了
BestCoder Round #67 (div.2) 1001——N bulbs
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定一個長度為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");} }總結
以上是生活随笔為你收集整理的BestCoder Round #67 (div.2) 1001——N bulbs的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML富文本中,如何实现加粗按钮后,输
- 下一篇: 成都大熊猫繁育研究基地坐几路公交车