NEU 1495 a interesting game 大数 难度:1
问题 G: a interesting game
时间限制: 1 Sec 内存限制: 128 MB提交: 29 解决: 10
[提交][状态][讨论版]
题目描述
One day,Kid is in class.But Kid think what the teacher teaching is so boring,so he decide to play a
game with himself.He will give himself a matrix with n rows and m columns.Then for each
position,Kid will write 0 or 1 on it.Kid want to find that there are how many schemes that for each
row and each column the number of 1 is odd.
输入
The first line is a integer t,the number of case.
Then for each case,there are two numbers,n and m,(1<=n,m<=100)implies the rows and the columns.
输出
For each case,output only one integer,the number of schemes.
样例输入
1 2 2
样例输出
2
题目链接:http://acm.neu.edu.cn/hustoj/problem.php?cid=1047&pid=6
思考:n行m列,如果n,m奇偶性不同肯定为0,否则前面的随便填充,最后一行一列状态补足条件,也就是2^((n-1)(m-1))
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception{ int T; Scanner in = new Scanner(System.in); T=in.nextInt(); for(int i=0;i<T;i++){ int n,m; n=in.nextInt(); m=in.nextInt(); if(n>m){int t=n;n=m;m=t;} if((n%2==1&&m%2!=1)||(m%2==1&&n%2!=1)){System.out.println("0");continue;} if(n==1){System.out.println("1");continue;} int t=(n-1)*(m-1)-1; BigInteger ans = BigInteger.valueOf(2).shiftLeft(t); System.out.println(ans); } } }