AtCoder Regular Contest 080 C - 4-adjacent
地址:http://arc080.contest.atcoder.jp/tasks/arc080_a
题目:
C - 4-adjacent
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a sequence of length N, a=(a1,a2,…,aN). Each ai is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
- For each 1≤i≤N−1, the product of ai and ai+1 is a multiple of 4.
Determine whether Snuke can achieve his objective.
Constraints
- 2≤N≤105
- ai is an integer.
- 1≤ai≤109
Input
Input is given from Standard Input in the following format:
N a1 a2 … aN
Output
If Snuke can achieve his objective, print Yes
; otherwise, print No
.
思路:求膜2为1,膜4为0的数有多少个就好了。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define MP make_pair 6 #define PB push_back 7 typedef long long LL; 8 typedef pair<int,int> PII; 9 const double eps=1e-8; 10 const double pi=acos(-1.0); 11 const int K=1e6+7; 12 const int mod=1e9+7; 13 14 int n,a,b,c,ans; 15 16 int main(void) 17 { 18 scanf("%d",&n); 19 for(int i=1,x;i<=n;i++) 20 { 21 scanf("%d",&x); 22 if(x%4==0) c++; 23 else if(x%2==0) b++; 24 else a++; 25 } 26 c-=a; 27 if(c>=0||(c==-1&&b==0)) puts("Yes"); 28 else puts("No"); 29 return 0; 30 }
作者:weeping
出处:www.cnblogs.com/weeping/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。