AcWing 3708. 求矩阵的鞍点

输入样例:

复制代码
3 4
1 2 3 4
1 2 3 4
1 2 3 4

输出样例:

复制代码
1 4 4
2 4 4
3 4 4
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int n,m,a[N][N],x[N],y[N],flag=1;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		int p=0;
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			p=max(p,a[i][j]);
		}
		x[i]=p;
	}
	for(int i=1;i<=m;i++){
		int p=10;
		for(int j=1;j<=n;j++){
			cin>>a[j][i];
			p=min(p,a[j][i]);
		}
		y[i]=p;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==x[i]&&a[i][j]==y[j]){
				cout<<i<<" "<<j<<" "<<a[i][j]<<endl;
				flag=0;	
			}
		}
	}
	if(flag) cout<<"NO";
	return 0;
}
相关推荐
ZPC82107 小时前
PPO算法训练机器人时,如何定义状态/动作/奖励
人工智能·算法·机器人
永远都不秃头的程序员(互关)8 小时前
数据结构实战:从复杂度到C++实现
算法
客梦8 小时前
数据结构-线性表
数据结构·笔记
努力学算法的蒟蒻8 小时前
day42(12.23)——leetcode面试经典150
算法·leetcode·面试
鹿角片ljp8 小时前
力扣226.翻转二叉树-递归
数据结构·算法·leetcode
TechNomad8 小时前
排序算法:归并排序算法
算法·排序算法
qq_310658518 小时前
janux源码走读(五)Janus事件处理模块(events/)
服务器·c++·音视频
WBluuue8 小时前
数据结构和算法:Morris遍历
数据结构·c++·算法
客梦8 小时前
数据结构-红黑树
数据结构·笔记
scx201310048 小时前
20251117Manacher总结
算法·manacher