官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uz2v.html
1 #include<cstdio> 2 const int M=100; 3 int a[M][M]; 4 int dx[]={0,0,1,-1}; 5 int dy[]={1,-1,0,0}; 6 int main(){ 7 int t,n,m; 8 while(~scanf("%d",&t)){ 9 while(t--){ 10 scanf("%d%d",&n,&m); 11 for(int i=0;i<n;i++){ 12 for(int j=0;j<m;j++){ 13 a[i][j]=1; 14 } 15 } 16 for(int i=0;i<n;i++){ 17 for(int j=0;j<m;j++){ 18 if((i+j)&1){ 19 a[i][j]=0; 20 for(int k=0;k<4;k++){ 21 int tx=i+dx[k]; 22 int ty=j+dy[k]; 23 if(tx>=0&&tx<n&&ty>=0&&ty<m){ 24 a[tx][ty]<<=1; 25 } 26 } 27 } 28 } 29 } 30 int sum=0; 31 for(int i=0;i<n;i++){ 32 for(int j=0;j<m;j++){ 33 sum+=a[i][j]; 34 } 35 } 36 printf("%d\n",sum); 37 } 38 } 39 return 0; 40 }