题目1001:A+B for Matrices
题目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的更多相关文章
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 题目1001:A+B for Matrices(简单循环)
问题来源 http://ac.jobdu.com/problem.php?pid=1001 问题描述 给你两个形式相同的矩阵,对应位置相加得到新矩阵,计算里面全为0的行数和列数. 问题分析 这里其实只 ...
- shell练习--PAT题目1001:卡拉兹(Callatz)猜想(失败案例)
卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 ( 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 年的世界 ...
- pat甲级题目1001 A+B Format详解
pat1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits ...
- SCNU 2015ACM新生赛初赛【1001~1011】个人解题思路
题目1001: 大意:已知$n$个角色,$m$种怪物种族,$k$个怪物,给出一组角色编号,编号$P_{i}$的角色能肝死编号$i$的怪物,对于给定的一组怪物编号,为了打通关 ...
- 九度OJ-1001-A+B矩阵-有些小技巧
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:22974 解决:9099 题目描述: This time, you are supposed ...
- BestCoder Round #60 题解链接
题解 题目 1001 GT and sequence 注意先特判000的情况:如果读入的数据有000,那么去掉所有的000且最后答案和000取一个max. 剩下的正数显然全部乘起来比较优. 对于负数 ...
- 311. Sparse Matrix Multiplication
题目: Given two sparse matrices A and B, return the result of AB. You may assume that A's column numbe ...
- codevs 版刷计划(1000-1099)
Diamond咋都是模板题... 开个坑刷codevs的Master题.巩固一下姿势. 目前AC的题目:1001,1021,1022, 1001.舒适的路线(并查集) 求出无向图s到t路径上的min( ...
随机推荐
- JavaScript页面跳转的一些实现方法
第一种 <script language=”javascript” type=”text/javascript”> window.location.href=”login.jsp?back ...
- python 文件分割
import sys,os def split(fromfile,todir,chunksize): partnum = inputfile = open(fromfile,'rb')#open th ...
- chrome表单自动填充去掉input黄色背景
input文本框是纯色背景的 1. input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset!important; ...
- 899F - Letters Removing
Codeforces 899F - Letters Removing 思路:考虑一下怎么找到输入的l和r在原来串中的位置,我们想到用前缀和来找,一开始所有位置都为1,删掉后为0,那么前缀和为l的位置就 ...
- Html概述
Html概述 主要思想,主要思想很重要 一.Html是什么 一种标记语言(用标签进行标记) 对要显示的文字进行标记 二.Html核心 标签(只认标签) 封装,所以必须有头尾,你才知道标签的范围,你才知 ...
- eclipse wtp 没有自动生成 web.xml
因此,运行servlet 时出错了. 网上查了一下,好像说确实不会自动生成,但是运行应该没有问题的. 幸亏找到了手动生成web.xml的方法,也就不纠结了. http://crunchify.com/ ...
- SSH Secure Shell Client--- the host may be dow
the host may be down,or there may be a problem with the network connection. Sometimes such problems ...
- Confluence 6 教程:在 Confluence 中导航
当你对 Confluence 有所了解后,你会发现 Confluence 使用起来非常简单.这个教程主要是针对你使用的 Confluence 界面进行一些说明,同时向你展示在那里可以进行一些通用的任务 ...
- poj 1182 (带权并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 71361 Accepted: 21131 Description ...
- Linux文件删除,但是df之后磁盘空间没有释放
Linux 磁盘空间总是报警,查到到大文件,删除之后,df看到磁盘空间并没有释放. 查找了下发现系统对rm进行了alias ,因为Linux对删除操作没有回收站机制,对rm操作进行了自定义,对删除 ...