官方解题报告: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 }
View Code

相关文章:

  • 2021-12-06
  • 2021-11-13
  • 2022-01-06
  • 2022-01-10
  • 2021-06-07
猜你喜欢
  • 2021-10-10
  • 2022-01-21
  • 2021-07-24
  • 2021-08-26
  • 2021-08-20
  • 2021-10-12
  • 2021-07-12
相关资源
相似解决方案