题目描述:

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 -60

样例输出:

1

5

简单翻译一下

先输入矩阵行和列的数,再列出2个矩阵的数字,然后矩阵相加,算出行数都是零和列数都是零的总和。

Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class Main { public static void main(String[] args) {
List<Integer> mList = new ArrayList<Integer>();
Scanner cin = new Scanner(System.in);
int rows;
while ((rows = cin.nextInt()) != 0) {
int columns;
int totalTmp = 0;
int total = 0;
columns = cin.nextInt();
int[][] arrays1 = new int[rows][columns];
int[][] arrays2 = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
arrays1[i][j] = cin.nextInt();
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
arrays2[i][j] = cin.nextInt();
totalTmp = totalTmp | (arrays1[i][j] + arrays2[i][j]);
}
if (totalTmp == 0) {
total++;
}
totalTmp = 0;
} for (int colum = 0; colum < columns; colum++) {
for (int row = 0; row < rows; row++) {
totalTmp = totalTmp
| (arrays1[row][colum] + arrays2[row][colum]);
}
if (totalTmp == 0) {
total++;
}
totalTmp = 0;
}
mList.add(total);
}
for (int num : mList) {
System.out.println(num + "");
} }
}

我是天王盖地虎的分割线

九度oj-1001-Java的更多相关文章

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

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

  2. 九度OJ 1001:A+B for Matrices

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17682 解决:7079 题目描述: This time, you are supposed to find A+B where A and ...

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

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

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

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

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

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

  6. hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

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

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

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

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

  9. 【九度OJ】题目1040:Prime Number 解题报告

    [九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...

  10. 【九度OJ】题目1163:素数 解题报告

    [九度OJ]题目1163:素数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1163 题目描述: 输入一个整数n(2< ...

随机推荐

  1. poj 2599 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<cstdio> #include<cmath> #include<algorithm> #includ ...

  2. BZOJ4280 : [ONTAK2015]Stumilowy sad

    线段树每个区间维护上下界以及要整体增加的标记即可,时间复杂度$O(m\log n)$. #include<cstdio> #define inf 1500000000 int n,m,op ...

  3. 【转载】EmptyWorkingSet 程序运行内存整清理

    网络上找了很多关于内存整理的文章,不外乎都是使用EmptyWorkingSet来实现.就如下面这段代码. #include "stdafx.h"#include <windo ...

  4. HDU 5908 Abelian Period 暴力

    Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...

  5. bash编程之xargs实用技巧

    xargs结合管道操作符|,可以完成很多看似复杂的问题: 1.快速删除所有.log日志文件 机器运行久了,就会有各式各样的日志文件,散落在各个目录下,可以利用下面的方法: find ./ -name ...

  6. uva 10154 - Weights and Measures【dp】qi

    题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包含自己的所有的重量. 分析:先按其能举起来的力量从小 ...

  7. Serial Wire Debug (SWD) Interface -- PSoc5

    PSoC 5 supports programming through the serial wire debug (SWD) interface. There are two signals in ...

  8. ASP.NET Web API中通过ETag实现缓存

    通常情况下Server是无状态的,在ASP.NET Web API中,我们可以让服务端响应体中产生ETag属性,起到缓存的作用.大致实现原理是: 1.服务端的响应体中返回一个ETag属性2.客户端通过 ...

  9. CentOS 安装 Jenkins

    原文:https://www.sunjianhua.cn/archives/centos-jenkins.html 1.更换源 mv /etc/yum.repos.d/CentOS-Base.repo ...

  10. JavaScript 检查是否是数字

    //---------------------------------------------------------- // 功能:检查是否是数字 // 参数: // str // 返回值: // ...