05:サドルポイント計算

合計時間制限:65536kBの:メモリ制限を1000msの
説明は
5×5マトリックスを与え、そして各行は、各列の最小値のみ鞍点行列を見つける唯一の最大値を有します。
これは、行の最大値である行列の要素の鞍点を指し、カラムは最小値が配置されています。
たとえば、次の例では(鞍点要素は4行目に1、値8です)。
5. 6 9 3 11
12 10 4 7 8
10 5 11 9 6
。8 4 7 6 2
15 10 20 25 11であります

入力
入力は、5行のマトリクス5を含んでいる
出力
鞍点、カラムとその値がない場合、出力は「見つかりません」が出力鞍点がある場合行を
サンプル入力
11 3 5 6 9
12れる。4 7 8 10
10 5 9. 11. 6
。8 4 7 6 2
15 10 20 25 11である
サンプル出力
418

#include<iostream>
using namespace std;
int main(){
	int a[10][10];
	for(int row=1;row<=5;row++)                                //输入5*5个元素 
	for(int col=1;col<=5;col++){
		cin>>a[row][col];
	}
	
	
	int max[6],maxCol[6];                                      //max[i]表示第i行最大的元素值,maxCol[i]表示该元素所在的列
	for(int row=1;row<=5;row++){
		max[row]=a[row][1];
		maxCol[row]=1;
		for(int col=1;col<=5;col++)
		if(a[row][col]>max[row]){
			max[row]=a[row][col];
			maxCol[row]=col;
		}
	}
	
	
	                                                          //判断一行最大的元素max[row]是否为最大元素所在列maxCol[row]的最小元素
	for(int row=1;row<=5;row++){
		int flag=1;                                           //flag用来判断 
		for(int i=1;i<=5;i++){
			if(a[i][maxCol[row]]<max[row])
			flag=0;
		}
		if(flag==1){                                          // flag为0 表示元素所在的列有小于“行最大元素”的情况,表示其不再是该列的最小值 ,也就不符合题目行最大列最小的要求 
		                                                      // flag==1 表示该行row的最大值确实为该列maxCol[row]的最小值 
			cout<<row<<' '<<maxCol[row]<<' '<<a[row][maxCol[row]];
			return 0;
		}
	}
	
	cout<<"not found";
	
	
	
	return 0;
}
公開された36元の記事 ウォンの賞賛0 ビュー354

おすすめ

転載: blog.csdn.net/weixin_44437496/article/details/103997126