题目1001:A+B for Matrices

时间限制:1 秒内存限制:32 兆

题目描述:

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

----------------

代码有bug,测试数据不够严谨.  AC了。。。。

----------------------------------------------------

import java.util.Scanner;
public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int m=sc.nextInt();
if(m==0)break;
int n=sc.nextInt();
int a[][]=new int[m][n];
int b[][]=new int[m][n];
int c[][]=new int[m][n];
int zorerow=0;
int zorecol=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
for(int i=0;i<m;i++)
for(int j=0;j<n;j++){
b[i][j]=sc.nextInt();
c[i][j]=a[i][j]+b[i][j];
} int temp=0;
int tmp=0;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
temp+=c[i][j];
}
if(temp==0)zorerow++;
temp=0;
}
for(int j=0;j<n;j++){
for(int i=0;i<m;i++){
tmp+=c[i][j];
}
if(tmp==0)zorerow++;
tmp=0;
} System.out.println(zorerow+zorecol);
} } }

题目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. 题目1001:A+B for Matrices(简单循环)

    问题来源 http://ac.jobdu.com/problem.php?pid=1001 问题描述 给你两个形式相同的矩阵,对应位置相加得到新矩阵,计算里面全为0的行数和列数. 问题分析 这里其实只 ...

  3. shell练习--PAT题目1001:卡拉兹(Callatz)猜想(失败案例)

    卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 ( 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 年的世界 ...

  4. pat甲级题目1001 A+B Format详解

    pat1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits ...

  5. SCNU 2015ACM新生赛初赛【1001~1011】个人解题思路

            题目1001:       大意:已知$n$个角色,$m$种怪物种族,$k$个怪物,给出一组角色编号,编号$P_{i}$的角色能肝死编号$i$的怪物,对于给定的一组怪物编号,为了打通关 ...

  6. 九度OJ-1001-A+B矩阵-有些小技巧

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

  7. BestCoder Round #60 题解链接

    题解  题目 1001 GT and sequence 注意先特判000的情况:如果读入的数据有000,那么去掉所有的000且最后答案和000取一个max. 剩下的正数显然全部乘起来比较优. 对于负数 ...

  8. 311. Sparse Matrix Multiplication

    题目: Given two sparse matrices A and B, return the result of AB. You may assume that A's column numbe ...

  9. codevs 版刷计划(1000-1099)

    Diamond咋都是模板题... 开个坑刷codevs的Master题.巩固一下姿势. 目前AC的题目:1001,1021,1022, 1001.舒适的路线(并查集) 求出无向图s到t路径上的min( ...

随机推荐

  1. Django本地开发,debug模式引用静态文件

    debug为true ,不用设置static_root debug 为false ,设置static_root STATIC_ROOT = ( os.path.join(BASE_DIR, 'stat ...

  2. 《剑指offer》第一题(重载赋值运算符)

    //重载赋值运算符 #include <iostream> #include <cstring> using namespace std; class CMystring { ...

  3. C#代码安装、卸载、监控Windows服务

    C#编写Windows服务之后都不可避免的需要安装,卸载等操作.而传统的方式就是通过DOS界面去编写命令,这样的操作方式无疑会增加软件实施人员的工作量,下面就介绍一种简单.高效.快速方便的方式.1.安 ...

  4. PHP消息队列之Beanstalk

    Beanstalk,一个高性能.轻量级的分布式内存队列

  5. 雷林鹏分享:C# 不安全代码

    C# 不安全代码 当一个代码块使用 unsafe 修饰符标记时,C# 允许在函数中使用指针变量.不安全代码或非托管代码是指使用了指针变量的代码块. 指针变量 指针 是值为另一个变量的地址的变量,即,内 ...

  6. Enter键实现按钮相同功能

    1.在所在的按钮(Enter键功能)的容器上加上onkeydown="saveForKeyDown()",通常加载body上 <!-- 添加窗口--> <div ...

  7. git log 查找

    查找含有某个字符串的 commit git log --grep=224 // 这条命令是查看含有 "224" 关键字的 git commit 查看某个作者 git log --a ...

  8. 使用路径arc

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  9. React脚手架create-react-app+elementUI使用

    一.介绍 1.create-react-app是FaceBook官方发布了一个无需配置的.用于快速构建开发环境的脚手架工具. 2.优点 a.无需配置:官方的配置堪称完美,几乎不用你再配置任何东西,就可 ...

  10. jenkins邮件配置----jenkins笔记(三)

    转载地址:https://www.cnblogs.com/sylvia-liu/p/4527390.html 前言 最近搭建Maven+Testng+jenkins的持续集成环境,希望最后实现自动邮件 ...