当前位置:网站首页>-寻找鞍点-
-寻找鞍点-
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";
}
边栏推荐
猜你喜欢
【Biotin Azide|cas:908007-17-0】Price_Manufacturer
Harmony OS Date ano UI 】 【 】 the basic operation
Object类与常用API
Exception (abnormal) and Error (error) difference analysis
IO process thread -> thread -> day5
在树莓派上搭建属于自己的网页(2)
idea使用@Autowired注解爆红原因及解决方法
[Harmony OS] [ArkUI] ets development graphics and animation drawing
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
tag单调栈-单调栈预备知识-lt.739. 每日温度
随机推荐
NotImplementedError: file structure not yet supported
typescript42-readonly修饰符
Shell conditional statement judgment
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
web安全-sql注入漏洞
Benchmark 第一篇 了解Benchmark
ss-5.consul服务端+生产者+消费者
【转】最小描述长度准则MDL(Minimun Description Length)
MCM box model modeling method and source analysis of atmospheric O3
GIS数据漫谈(五)— 地理坐标系统
web安全-PHP反序列化漏洞
Secondary development of WinForm controls
typescript41-class类的私有修饰符
Newifi路由器第三方固件玩机教程,这个路由比你想的更强大以及智能_Newifi y1刷机_smzdm
Apache DolphinScheduler版本2.0.5分布式集群的安装
高效率科研神器——小软件、大能量
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
用scikit-learn学习谱聚类
Redis常用命令
数据分析 第一篇