2991. 鞍点

include

using namespace std;
int T;
int tu[5][5];
int Max[5],Min[5];
void solve()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cin>>tu[i][j];
for(int i=0;i<5;i++)
{
Max[i]=tu[i][0];
for(int j=1;j<5;j++) Max[i]=max(Max[i],tu[i][j]);
}
for(int j=0;j<5;j++)
{
Min[j]=tu[0][j];
for(int i=1;i<5;i++) Min[j]=min(Min[j],tu[i][j]);
}

int found=0;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
if(tu[i][j]==Max[i] && tu[i][j]==Min[j])
{
found=1;
cout<<i<<’ ‘<<j<<endl;
}
if(!found) cout<<”-1 -1”<>T;
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}

#include <cstdint>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
uint32_t t; cin >> t;
for (uint32_t query = 0; query < t; ++query) {
uint32_t matrix[5][5];
for (uint32_t i = 0; i < 5; ++i)
for (uint32_t j = 0; j < 5; ++j)
cin >> matrix[i][j];
bool row_max[5][5];
bool col_min[5][5];
memset(row_max, false, sizeof(row_max));
memset(col_min, false, sizeof(col_min));
for (uint32_t i = 0; i < 5; ++i) {
uint32_t crnt_max = matrix[i][0];
uint32_t crnt_min = matrix[0][i];
for (uint32_t j = 1; j < 5; ++j) {
if (crnt_max < matrix[i][j])
crnt_max = matrix[i][j];
if (crnt_min > matrix[j][i])
crnt_min = matrix[j][i];
}
for (uint32_t j = 0; j < 5; ++j) {
if (matrix[i][j] == crnt_max)
row_max[i][j] = true;
if (matrix[j][i] == crnt_min)
col_min[j][i] = true;
}
}
cout << "case #" << query << ":\n";
for (uint32_t i = 0; i < 5; ++i)
for (uint32_t j = 0; j < 5; ++j)
if (row_max[i][j] && col_min[i][j]) {
cout << i << ' ' << j << '\n';
}
cout << "-1 -1\n";
}
}


#include<iostream>

void solve();
using namespace std;

int main() {
int t;
cin >> t;

for (int i = 0; i != t; ++i) {
cout << "case #" << i << ":\n";
solve();
}
}

void solve() {
int matrix[5][5];
for (int i = 0; i != 5; ++i) {
for (int j = 0; j != 5; ++j) {
cin >> matrix[i][j];
}
}

// Calculate the minimal value of each column.
int min_of_column[5];
for (int i = 0; i != 5; ++i) {
min_of_column[i] = matrix[0][i];
for (int j = 1; j != 5; ++j) {
if (min_of_column[i] > matrix[j][i]) {
min_of_column[i] = matrix[j][i];
}
}
}

// Calculate the maximal value of each row.
int max_of_row[5];
for (int i = 0; i != 5; ++i) {
max_of_row[i] = matrix[i][0];
for (int j = 1; j != 5; ++j) {
if (max_of_row[i] < matrix[i][j]) {
max_of_row[i] = matrix[i][j];
}
}
}

// find every saddle point. Note that they are *in order* for we iterate with i in 0..5 and j in 0..5.
int cnt = 0; // count of saddle_points.
for (int i = 0; i != 5; ++i) {
for (int j = 0; j != 5; ++j) {
int val = matrix[i][j];
if (val == max_of_row[i] && val == min_of_column[j]) {
cnt += 1;
}
}
}

// output each.
if (cnt == 0) {
cout << "-1 -1\n";
} else {
for (int i = 0; i != cnt; ++i) {