网易笔试,本地IDE能AC,客户端通过率0%,到底什么问题
判断一个数组能不能有一种排列使得相邻数的乘积被4整除
#include <iostream>
#include <vector>
using namespace std;
bool isok(int m,int n,int q,int flag){
int t=q-m;if(flag==n) return true;
else{
if(m>=(n-t+1)) return true;
else if(((n-t+1)%2==1)&&(m>=n/2)) return true;
else {return false;}
}
}
int main(){
int t,i=0;
vector<bool> ss;
cin>>t;
while(i<t){ int n,flag=0; long long c=0; vector<long long> A,B,C;
cin>>n;
for(int j=0;j<n;j++){ cin>>c;
A.push_back(c);
if(c%2==0)
C.push_back(c);
if(c%4==0)
B.push_back(c);
if(c==2) flag++;
}
int m=B.size();
int q=C.size();
bool ok;
if((n==1)&&(A[0]%4!=0)) ok=false;
else{
ok=isok(m,n,q,flag);
}
ss.push_back(ok);
i++;
}
for(int k=0;k<ss.size();k++){
if(ss[k]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
查看31道真题和解析