当前位置:网站首页>-寻找鞍点-
-寻找鞍点-
2022-08-03 05:10:00 【-JMY-】
题目描述
给定一个5*5的矩阵,每行只有一个最大值,每列只有一个最小值,寻找这个矩阵的鞍点。鞍点指的是矩阵中的一个元素,它是所在行的最大值,并且是所在列的最小值。
例如:在下面的例子中(第4行第1列的元素就是鞍点,值为8 )。
11 3 5 6 9
12 4 7 8 10
10 5 6 9 11
8 6 4 7 2
15 10 11 20 25
输入
输入包含一个5行5列的矩阵
输出
如果存在鞍点,输出鞍点所在的行、列及其值,如果不存在,输出"not found"
样例输入
11 3 5 6 9 12 4 7 8 10 10 5 6 9 11 8 6 4 7 2 15 10 11 20 25
样例输出
4 1 8
参考代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[10][10],b=-1,c=1000,x=0,y=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
cin>>a[i][j];
}
}
for(int j=1;j<=5;j++)
{
for(int i=1;i<=5;i++)
{
if(a[j][i]>b){b=a[j][i];x=i;}
}
for(int i=1;i<=5;i++)
{
if(a[i][x]<c){c=a[i][x];y=i;}
}
if(c==b){cout<<y<<" "<<x<<" "<<c;return 0;}
b=-1;c=1000;x=0;y=0;
}
cout<<"not found";
}
边栏推荐
猜你喜欢
数据分析 第一篇
【特征选取】计算数据点曲率
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
轨迹(形状)相似性判断与度量方法
UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
Detailed explanation of MOSN reverse channel
GIS数据漫谈(六)— 投影坐标系统
IO process thread -> thread -> day5
breed Web刷机升级详细教材修正编译器固件说明_itkeji.top
Object类与常用API
随机推荐
HarmonyOS应用开发第一次培训
dataframe插入一列
Installation of Apache DolphinScheduler version 2.0.5 distributed cluster
Pr第四次培训笔记
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
Detailed explanation of MOSN reverse channel
HarmonyOS应用开发培训第二次作业
typescript45-接口之间的兼容性
第三次HarmonyOS培训
Length n of condensed distance matrix ‘y‘ must be a binomial coefficient
信息编码、存储压缩与密码学
生活原则。
Business table analysis - balance system
typescript46-函数之间的类型兼容性
2. 两数相加
Object类与常用API
GIS数据漫谈(五)— 地理坐标系统
获取Ip工具类
用户密码验证
阿里云对象存储oss私有桶生成链接