当前位置:网站首页>-寻找鞍点-
-寻找鞍点-
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";
}
边栏推荐
- UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
- BIOTIN ALKYNE CAS: 773888-45-2 Price, Supplier
- Installation of Apache DolphinScheduler version 2.0.5 distributed cluster
- typescript40-class类的保护修饰符
- The problem that the rosbag tool plotjuggler cannot open rosbag
- web安全-命令执行漏洞
- Shell conditional statement judgment
- HarmonyOS应用开发培训第二次作业
- ss-4.2 多个eureka集群案例
- Apache DolphinScheduler版本2.0.5分布式集群的安装
猜你喜欢
Build your own web page on raspberry pie (1)
Unity2D horizontal board game tutorial 6 - enemy AI and attack animation
曲线特征----曲线弯曲程度的探究
idea使用@Autowired注解爆红原因及解决方法
typescript40-class类的保护修饰符
web安全-命令执行漏洞
Talking about GIS Data (5) - Geographic Coordinate System
typescript39-class类的可见修饰符
传说中可“免费白拿”的无线路由器 - 斐讯 K2 最简单刷 breed 与第三方固件教程
如何不耍流氓的做运维之-SHELL脚本
随机推荐
Fluorescent marker peptides FITC/AMC/FAM/Rhodamine TAMRA/Cy3 / Cy5 / Cy7 - Peptide
odps的临时查询能在写sql的时候就给结果一个命名不?
Harmony OS Date ano UI 】 【 】 the basic operation
HarmonyOS应用开发第一次培训
数字孪生园区场景中的坐标知识
13.< tag-动态规划和回文字串>lt.647. 回文子串 + lt.516.最长回文子序列
typescript40-class类的保护修饰符
GIS数据漫谈(五)— 地理坐标系统
C# async and multithreading
第四次培训
Interface test Mock combat (2) | Combined with jq to complete batch manual Mock
2. 两数相加
Alienware上线首个数字时装AR试穿体验
Lambda表达式案例
typescript41-class类的私有修饰符
【转】最小描述长度准则MDL(Minimun Description Length)
斐讯K2路由编译Padavan华硕固件和心得
Super handy drawing tool is recommended
1095 解码PAT准考证 (25 分)(C语言)
Detailed explanation of MOSN reverse channel