1235: 计算矩阵的鞍点

题目

  输出二维数组中行上为最大,列上为最小的元素(称为鞍点)及其位置(行列下标)。如果不存在任何鞍点,请输出"404 not found"(不带引号)。更多内容点击标题。

分析

  没什么好分析的,只要看懂下面这几组数据就明白了。

输入

2
2 2
1 1
1 1 2 2
2 3
1 3

输出

1 1 1
1 1 2
1 2 1
1 2 2
3 1 2
3 2 2

代码

/**
* time 1248ms
* @author PengHao
* @version A2.0
* @date 2019-04-21 下午8:16:45
*/ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer; public class Main { /**
* Input and Output
*
* @author PengHao
* @version 1.0
* @date 2019年4月21日 下午7:14:20
*/
private static class IO {
// 输入部分
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StreamTokenizer st = new StreamTokenizer(br); public int nextInt() {
try {
st.nextToken();
} catch (IOException e) {
e.printStackTrace();
}
return (int) st.nval;
} // 输出部分
OutputStreamWriter osw = new OutputStreamWriter(System.out);
PrintWriter pw = new PrintWriter(osw); void print(int x) {
pw.print(x);
pw.flush();
} void print(String s) {
pw.print(s);
pw.flush();
} void println() {
pw.println();
pw.flush();
} void println(String s) {
pw.println(s);
pw.flush();
} void println(int a, int x, int y) {
print(a);
print(" ");
print(x);
print(" ");
print(y);
println();
}
} private IO io = new IO();
private int n, m;
private int[][] matrix; // 矩阵 public Main() {
int t;
matrix = new int[23][23];
boolean flag;
t = io.nextInt();
while ((t--) > 0) {
input();
flag = true; // 初始没找到鞍点
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (largest(i, j) && smallest(i, j)) {
io.println(matrix[i][j], i, j);
flag = false;
}
}
}
if (flag) {
io.println("404 not found");
}
}
} /**
* Input data
*/
private void input() {
n = io.nextInt();
m = io.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
matrix[i][j] = io.nextInt();
}
}
} /**
* @param x 行下标
* @param y 列下标
* @return true 如果这个数是这一行最大的数
*/
private boolean largest(int x, int y) {
for (int j = 1; j <= m; j++) {
if (matrix[x][j] > matrix[x][y]) {
return false;
}
}
return true;
} /**
* @param x 行下标
* @param y 列下标
* @return true 如果这个数是这一列最小的数
*/
private boolean smallest(int x, int y) {
for (int i = 1; i <= n; i++) {
if (matrix[i][y] < matrix[x][y]) {
return false;
}
}
return true;
} public static void main(String[] args) {
new Main();
} }

代码补充

  类IO有点长,就是个输入输出的功能,同Scanner(输入)和println(输出)一样,我只是听说Scanner读取比较慢,就用的这种方法。


写在最后:

  1. 如需转载,请于标题下注明链接形式的wowpH的博客即可;
  2. 代码原创,如需公开引用,不能删除首行注释(作者,版本号,时间等信息)。
  3. 如果有疑问欢迎评论留言,尽力解答。

WUSTOJ 1235: 计算矩阵的鞍点(Java)的更多相关文章

  1. 【原创】开源Math.NET基础数学类库使用(15)C#计算矩阵行列式

                   本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新  开源Math.NET基础数学类库使用总目录:[目录]开源Math.NET基础数学类库使用总目录 上个月 ...

  2. 【原创】开源Math.NET基础数学类库使用(16)C#计算矩阵秩

                   本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新  开源Math.NET基础数学类库使用总目录:[目录]开源Math.NET基础数学类库使用总目录 上个月 ...

  3. 【原创】开源Math.NET基础数学类库使用(17)C#计算矩阵条件数

                   本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新  开源Math.NET基础数学类库使用总目录:[目录]开源Math.NET基础数学类库使用总目录 上个月 ...

  4. Openjudge计算概论-计算矩阵边缘元素之和

    /*======================================================================== 计算矩阵边缘元素之和 总时间限制: 1000ms ...

  5. POJ C程序设计进阶 编程题#1:计算矩阵边缘之和

    编程题#1:计算矩阵边缘元素之和 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB ...

  6. 开源Math.NET基础数学类库使用(17)C#计算矩阵条件数

    原文:[原创]开源Math.NET基础数学类库使用(17)C#计算矩阵条件数                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...

  7. 开源Math.NET基础数学类库使用(16)C#计算矩阵秩

    原文:[原创]开源Math.NET基础数学类库使用(16)C#计算矩阵秩                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4 ...

  8. 开源Math.NET基础数学类库使用(15)C#计算矩阵行列式

    原文:[原创]开源Math.NET基础数学类库使用(15)C#计算矩阵行列式                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...

  9. matlab计算矩阵每列非0元素个数

    在统计分析中,有时候需要计算矩阵每列非0元素的个数,可以用以下方法: 先用find找到每列不为0的元素index,然后用count计数. 假设有矩阵A[M,N], 结果存在countZeros cou ...

随机推荐

  1. mysql5.7 源码安装步骤

    操作系统:centos 7 mysql版本:5.7  下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-gli ...

  2. Linux下如何回到根目录

    cd .. , 意思是到上一级目录: cd - ,意思是返回到上次的目录,类似windows返回 : cd /,意思是回到根目录.

  3. ubuntu中编译安装gcc 9.2.0

    一切都和其他源码安装软件是一样的: 一.下载源代码: http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz 二.解压文件 tar xvf gcc- ...

  4. Java 方法与数组

    方法 什么是方法? 方法定义:方法(Method),函数(function),其实就指一个特定的功能操作,程序中完成独立功能,可重复使用的一段代码的集合. 方法的定义 方法定义格式: [修饰符] 返回 ...

  5. kvm网卡配置

    https://blog.51cto.com/quliren/2046001 https://blog.51cto.com/quliren/2045555 https://blog.csdn.net/ ...

  6. Flutter移动电商实战 --(43)详细页_补充首页跳转到详细页

    首页轮播点击到详细页 修改我们轮播这里的代码:SwiperDiy这个类这里的代码 return InkWell( onTap: (){ Application.router.navigateTo(co ...

  7. How to transform the day time images to night time ? A series of paper review and some thinkings about this point.

    How to transform the day time images to night time ?  A series of paper review and some thinkings ab ...

  8. 留个纪念,过了这么多年,又干回Android了!

    这个博客中的好多Android知识已经老得不像样子了,没想到,还有干回来的一天.怎么说呢,只要坚持一下,总会有机会能做自己爱做的事情的. 加油! ---- 于武汉出差的第5天

  9. 在基于acpi的linux系统上如何检查当前系统是否支持深度睡眠?

    答: 执行以下命令: # dmesg|grep -i acpi |grep -i supports (S3表示支持深度睡眠) ACPI: (supports S0 S1 S3 S4 S5)

  10. MyBatis 插件之拦截器(Interceptor)

    参考 https://blog.csdn.net/weixin_39494923/article/details/91534658 //项目实际使用  就是在你进行数据库操作时,进行数据的第二次封装 ...