题目1001:A+B for Matrices

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:22974

解决:9099

题目描述:

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.

样例输入:
  1. 2 2
  2. 1 1
  3. 1 1
  4. -1 -1
  5. 10 9
  6. 2 3
  7. 1 2 3
  8. 4 5 6
  9. -1 -2 -3
  10. -4 -5 -6
  11. 0
样例输出:
  1. 1
  2. 5
来源:
2011年浙江大学计算机及软件工程研究生机试真题
  1. #include <stdio.h>
  2. int ma[][];
  3. int mb[][];
  4.  
  5. int main() {
  6. int a, b;
  7. while(scanf("%d", &a)) {
  8.  
  9. if(a == ) return ;
  10. scanf("%d", &b);
  11.  
  12. for(int i = ; i < a; i++) {
  13. for(int j = ; j < b; j++) {
  14. scanf("%d", &ma[i][j]);
  15. }
  16. }
  17. for(int i = ; i < a; i++) {
  18. for(int j = ; j < b; j++) {
  19. scanf("%d", &mb[i][j]);
  20. mb[i][j] += ma[i][j];
  21. }
  22. }
  23.  
  24. // sum
  25. int su = ;
  26. int co = ;
  27. for(int i = ; i < a; i++) {
  28. for(int j = ; j < b; j++) {
  29. if(mb[i][j] != ){
  30. co++;
  31. // printf("%d %d\n", i, j);
  32. break;
  33. }
  34.  
  35. }
  36. if(co == ) {
  37. su++;
  38. // printf("%d %d\n", i, su);
  39. }
  40. else co = ;
  41. }
  42.  
  43. co = ;
  44. for(int j = ; j < b; j++) {
  45. for(int i = ; i < a; i++) {
  46. if(mb[i][j] != ) {
  47. co++;
  48. break;
  49. }
  50.  
  51. }
  52. if(co == ) {
  53. su++;
  54. }
  55. else co = ;
  56. }
  57.  
  58. printf("%d\n", su);
  59. }
  60. return ;
  61. }

九度OJ-1001-A+B矩阵-有些小技巧的更多相关文章

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

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

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

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

  3. 九度OJ 1534 数组中第K小的数字 -- 二分查找

    题目地址:http://ac.jobdu.com/problem.php?pid=1534 题目描述: 给定两个整型数组A和B.我们将A和B中的元素两两相加可以得到数组C. 譬如A为[1,2],B为[ ...

  4. 【九度OJ】题目1474:矩阵幂 解题报告

    [九度OJ]题目1474:矩阵幂 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1474 题目描述: 给定一个n*n的矩阵,求该矩阵的 ...

  5. 【九度OJ】题目1193:矩阵转置 解题报告

    [九度OJ]题目1193:矩阵转置 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1193 题目描述: 输入一个N*N的矩阵,将其转置 ...

  6. 【九度OJ】题目1191:矩阵最大值 解题报告

    [九度OJ]题目1191:矩阵最大值 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1191 题目描述: 编写一个程序输入一个mXn的 ...

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

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

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

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

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

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

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

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

随机推荐

  1. API验证插件

    前言 如果在访问某WebAPI过程中request信息被他人截获,若是get请求获取数据还好,如果是post提交数据,势必威胁数据安全,所以对于一个对安全性要求较高的API来说,对每个请求做身份验证显 ...

  2. provider和consumer配置参数的优先级

    <dubbo:service>和<dubbo:reference>存在一些相同的参数,例如:timeout,retries等,那么哪个配置的优先级高呢? consumer合并u ...

  3. 漫谈moosefs中cgi各项的意义

    原创:http://www.cnblogs.com/bugutian/p/6869278.html 转载请注明出处 一.先上一张图 二.解释 1. Metadata Servers (masters) ...

  4. MySQL设置白名单教程

    1 登录mysql mysql -h host -u username -p password 2 切换至mysql库 use mysql; 3 查看当前允许登录IP及用户 select Host,U ...

  5. Python获取时间戳

    import datetime as dt dt.datetime.now().microsecond

  6. python(3)之字符串

    字符串常用操作如下: name="huang yuqing"print(name.count("h"))#计算包含字符的个数print(name.capital ...

  7. Jquery如何禁止鼠标右键菜单

    jquery中使用contextmenu事件,如果返回true,则允许右键菜单:如果返回false,则禁止右键菜单 导入文件 <script type="text/javascript ...

  8. C++11 并发之std::thread std::mutex

    https://www.cnblogs.com/whlook/p/6573659.html (https://www.cnblogs.com/lidabo/p/7852033.html) C++:线程 ...

  9. Django+Xadmin+Echarts动态获取数据legend颜色显示灰色问题已解决

    前段时间做的使用Django的Xadmin后台和百度Echarts进行后台数据可视化,功能虽然实现,展示出来的legend图例,都是灰色的,只有鼠标放上去才会显示彩色的.百度都快被我刨穿了,看到有类似 ...

  10. OO第一阶段总(休)结(养)分(生)析(息)

    第一次作业: 这是一次让我认识到ddl面前潜力真的可以无限大的作业. 一直以为OO是一门和数据结构一样先用几周的时间讲讲Java然后写写”Hello World”小程序再开始讲正课的我(我也不知道为什 ...