时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:17682

解决:7079

题目描述:

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
来源:
2011年浙江大学计算机及软件工程研究生机试真题

思路:

本题的意思是计算两个矩阵的和中, 全0行和全0列的个数。

代码:

#include <stdio.h>

#define N 10

int main(void)
{
int m, n, i, j;
int a[N][N], b[N][N]; while (scanf("%d", &m) != EOF)
{
if (m == 0)
break; scanf("%d", &n);
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
int count = 0;
for(i=0; i<m; i++)
{
int zerorow = 1;
for(j=0; j<n; j++)
{
scanf("%d", &b[i][j]);
a[i][j] += b[i][j];
if (a[i][j] != 0)
zerorow = 0;
}
count += zerorow;
}
for(j=0; j<n; j++)
{
int zerocol = 1;
for(i=0; i<m; i++)
{
if (a[i][j] != 0)
zerocol = 0;
}
count += zerocol;
} printf("%d\n", count);
} return 0;
}
/**************************************************************
Problem: 1001
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/

九度OJ 1001:A+B for Matrices的更多相关文章

  1. 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题

    题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...

  2. 九度OJ 题目1384:二维数组中的查找

    /********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...

  3. 九度oj题目&amp;吉大考研11年机试题全解

    九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码).    http://ac.jobdu.com/problem.php?pid=11 ...

  4. 【九度OJ】题目1069:查找学生信息 解题报告

    [九度OJ]题目1069:查找学生信息 解题报告 标签(空格分隔): 九度OJ [LeetCode] http://ac.jobdu.com/problem.php?pid=1069 题目描述: 输入 ...

  5. 【九度OJ】题目1174:查找第K小数 解题报告

    [九度OJ]题目1174:查找第K小数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1174 题目描述: 查找一个数组的第 ...

  6. 【九度OJ】题目1181:遍历链表 解题报告

    [九度OJ]题目1181:遍历链表 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1181 题目描述: 建立一个升序链表并遍历输出. ...

  7. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  8. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  9. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

随机推荐

  1. vim+python

    #!/bin/bash # install fisa vim config echo '===============================' echo 'start to install ...

  2. 转:如何查看MyEclipse包含的Eclipse的版本号

    如何查看MyEclipse包含的Eclipse的版本号 博客分类: 技术 myeclipseeclipse  说到Eclipse的版本号,可能只有在安装插件时才会需要到,有人就曾在安装svn时为了找到 ...

  3. 3D数学读书笔记——矩阵基础番外篇之线性变换

    本系列文章由birdlove1987编写.转载请注明出处. 文章链接:http://blog.csdn.net/zhurui_idea/article/details/25102425 前面有一篇文章 ...

  4. 使用RTTI为继承体系编写”==”运算符

    转载请注明出处:http://www.cnblogs.com/inevermore/p/4012079.html   RTTI,指的是运行时类型识别技术.   先看一个貌似无关的问题:   为继承体系 ...

  5. react-native 封装 VedioPlayer 组件

    1.封装组件 src/components/VideoPlayer/index.js /** * 视频播放器 组件(VideoPlayer) */ import React, {Component} ...

  6. Deferred Shader GBuffer 感性认识。。。

  7. oracle 序列重置

    问题一:怎样重置oracle序列 oracle序列创建以后,假设想重置序列从 0 開始,逐渐递增1,能够採用例如以下存储过程: create or replace procedure reset_se ...

  8. C#利用SharpZipLib解压或压缩文件(支持多层目录递归压缩)

    需要下载ICSharpCode.SharpZipLib.dll using System; using System.Collections.Generic; using System.Linq; u ...

  9. shader之旅-7-平面阴影(planar shadow)

    根据<real-time shadow>这本书第二章中的推导,实现了最简单的阴影技术. planar shadow通过一个投影矩阵将被灯光照射的物体的顶点沿着光线方向投影到接受阴影的平面. ...

  10. windows下简单配置squid反向代理服务器

    下载windwosNT版本的squid下载地址: http://squid.acmeconsulting.it/download/squid-2.6.STABLE13-bin.zip 1.把squid ...