AtCoder Regular Contest 080 ---C 4-adjacent(考虑不全面,bug)

题目描述:

                                               C - 4-adjacent

Problem Statement

We have a sequence of length NN, a=(a1,a2,...,aN)a=(a1,a2,...,aN). Each aiai is a positive integer.

Snuke's objective is to permute the element in aa so that the following condition is satisfied:

  • For each 1≤i≤N−1, the product of aiai and ai+1ai+1 is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

  • 2≤N≤105
  • aiai is an integer.
  • 1≤ai≤109

Input

Input is given from Standard Input in the following format:

NN
a1a1 a2a2 ...... aNaN

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1 Copy

Copy

3
1 10 100

Sample Output 1 Copy

Copy

Yes

One solution is (1,100,10)(1,100,10).

Sample Input 2 Copy

Copy

4
1 2 3 4

Sample Output 2 Copy

Copy

No

It is impossible to permute aa so that the condition is satisfied.

Sample Input 3 Copy

Copy

3
1 4 1

Sample Output 3 Copy

Copy

Yes

The condition is already satisfied initially.

Sample Input 4 Copy

Copy

2
1 1

Sample Output 4 Copy

Copy

No

Sample Input 5 Copy

Copy

6
2 7 1 8 2 8

题意:

      给出N个数,问能不能产生一种排列,使得相邻两数的乘积均为4的倍数。

思路:

       显然,可以考虑每个数因子2的个数,然后想了好一会,发现一般情况下只要因子2个数为0的数数目<=因子个数>=2的数目即可,同时发现三个数例如:1 4 1的时候要特殊考虑,第一次WA的bug:没有将该种情况推广出去(即不存在因子2个数==1的数时),片面的认为只有这一种特殊情况,所以WA。

代码实现:

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 1ll<<60
using namespace std;
const int N=2e5+100;
const int M=4e5+100;
const int mod=1e9+7;
LL cal(LL x){
	
	LL num=0;
	while(x%2==0){
		num++;
		x/=2;
		
	}
	return num;
}
int main(){
	LL n;
	while(cin >> n){
		
		LL x,num1=0,num2=0,num3=0;
		
		for(int i=1;i<=n;i++){
			
			
			cin>>x;
			int num=cal(x);
			if(num==0){
				num1++;
			}else if(num==1)num2++;
			else num3++;
		}
		int ans=0;
		if(num2==0&&n!=2){
			if(num3>=num1-1)ans=1;
			else ans=0;
			
		}else{
			if(num3>=num1)ans=1;
			else ans=0;
		}
		if(ans)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
	
}

 

THE END;

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值