A+B for Matrices

 

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4483

解决:1938

题目描述:

    This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns.

输入:

    The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matrices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B.

    The input is terminated by a zero M and that case must NOT be processed.

输出:

    For each test case you should output in one line the total number of zero rows and columns of A+B.

样例输入:
2 2
1 1
1 1
-1 -1
10 9
2 3
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6
0
样例输出:
1
5

 

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <cstring>
  6 #include <cctype>
  7 
  8 #include <vector>
  9 #include <list>
 10 #include <deque>
 11 #include <string>
 12 #include <algorithm>
 13 #include <stack>
 14 #include <queue>
 15 #include <map>
 16 #include <set>
 17 
 18 using namespace std;
 19 
 20 
 21 int a[14][14];
 22 int b[14][14];
 23 
 24 
 25 
 26 int main()
 27 {
 28 
 29 
 30 
 31 
 32     int m,n;
 33 
 34     int i,j,k;
 35 
 36     while(scanf("%d",&m)!=EOF)
 37     {
 38         if(m==0)
 39             break;
 40 
 41         scanf("%d",&n);
 42 
 43         for(i=1;i<=m;i++)
 44         {
 45             for(j=1;j<=n;j++)
 46             {
 47                 scanf("%d",&a[i][j]);
 48             }
 49         }
 50 
 51         
 52         for(i=1;i<=m;i++)
 53         {
 54             for(j=1;j<=n;j++)
 55             {
 56                 scanf("%d",&b[i][j]);
 57             }
 58         }
 59 
 60         
 61 
 62         for(i=1;i<=m;i++)
 63         {
 64             for(j=1;j<=n;j++)
 65             {
 66                 a[i][j]+=b[i][j];
 67 
 68             }
 69         }
 70 
 71         int num=0;
 72 
 73 
 74 
 75         for(i=1;i<=m;i++)
 76         {
 77             for(j=1;j<=n;j++)
 78             {
 79                 if(a[i][j])
 80                     break;
 81             }
 82             if(j>n)
 83                 num++;
 84 
 85         }
 86 
 87 
 88         for(i=1;i<=n;i++)
 89         {
 90             for(j=1;j<=m;j++)
 91             {
 92             if(a[j][i])
 93                 break;
 94             }
 95 
 96             if(j>m)
 97                 num++;
 98         }
 99 
100         
101 
102         printf("%d\n",num);
103     }
104         
105 
106         
107 
108 
109     return 0;
110 }

 

posted @ 2012-05-30 18:44  cseriscser  阅读(324)  评论(0编辑  收藏  举报