解题思路: 分别统计奇数和偶数
ans!=0时
ans=2^(odd-1+even)
注意事项:
参考代码:
import java.util.Scanner;
public class 数组分割 {
/*
2
2
6 6
2
1 6
* */
static long mod=1000000007;
static int cifang;
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int T=scanner.nextInt();
while(T>0) {
T--;
int n=scanner.nextInt();
int even=0;
int odd=0;
cifang=0;
for(int i=1;i<=n;i++) {
int num=scanner.nextInt();
if(num%2==0)
even++;
else {
odd++;
}
}
// System.out.println(even+" even");
// System.out.println(odd+" odd");
if(odd==0&&even>0){
cifang = even;
}
// System.out.println(Math.pow(2, even)%mod);
else if(odd%2==0)
cifang =odd-1+even;
else {
cifang=-1;
}
// System.out.println(cifang+" p");
long ans=1;
if(cifang==-1)
System.out.println(0);
else {
while(cifang>0)
{
ans=(ans*2)%mod;
cifang--;
}
System.out.println(ans);
// System.out.println(" "+odd+" "+even);
}
}
}
}
0.0分
9 人评分
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:540 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:780 |
简单的a+b (C语言代码)浏览:460 |
小O的图案 (C语言代码)浏览:912 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:800 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:4364 |
A+B for Input-Output Practice (I) (C++代码)浏览:628 |
文件操作浏览:655 |
【蟠桃记】 (C语言代码)浏览:805 |
10进制 VS 2进制浏览:1048 |