其他分享
首页 > 其他分享> > H - Perfect Ban Gym - 101341H

H - Perfect Ban Gym - 101341H

作者:互联网

H - Perfect Ban Gym - 101341H (暴力)

题意:给出一个矩阵,删掉一行一列之后让剩余的元素中最大值是最小的。
Constantine and Mike are playing the board game «Wrath of Elves». There are n races and m classes of characters in this game. Each character is described by his race and class. For each race and each class there is exactly one character of this race and this class. The power of the character of the i-th race and the j-th class equals to aij, and both players know it perfectly.

Now Constantine will choose a character for himself. Before that Mike can ban one race and one class so that Constantine would not be able to choose characters of this race or of this class. Of course, Mike does his best to leave Constantine the weakest possible character, while Constantine, on the contrary, chooses the strongest character. Which race and class Mike should ban?

Input
The first line contains two integers n and m (2 ≤ n, m ≤ 1000) separated by a space — the number of races and classes in the game «Wrath of Elves», correspondingly.

The next n lines contain m integers each, separated by a space. The j-th number in the i-th of these lines is aij (1 ≤ aij ≤ 109).

Output
In the only line output two integers separated by a space — the number of race and the number of class Mike should ban. Races and classes are numbered from one. If there are several possible answers, output any of them.

Examples
Input
2 2
1 2
3 4
Output
2 2
Input
3 4
1 3 5 7
9 11 2 4
6 8 10 12
Output
3 2

思路:非常纯粹的暴力,我是先找出最大值,分别求出删除其对应行和列之后的最大值,然后再删去当下的这个最大值对应的列和行求得剩下的元素里面的最大值,取剩下的最大值最下的那种方案。

#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
int a[maxn][maxn];
struct node
{
    int x;
    int y;
    int num;
} str1, str2, str3, str4, str5;

int main()
{
    int xx, yy;
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    str1.num = 0;
    str2.num = 0;
    str3.num = 0;
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < m; j ++)
        {
            cin >> a[i][j];
            if(str1.num<a[i][j])
            {
                str1.num = a[i][j];
                str1.x = i;
                str1.y = j;
            }
        }
    }
    for(int i = 0; i < n; i ++)
    {
        if(i == str1.x)
            continue;
        for(int j = 0; j < m; j ++)
        {
            if(str2.num<a[i][j])
            {
                str2.num = a[i][j];
                str2.x = i;
                str2.y = j;
            }
        }
    }

    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < m; j ++)
        {
            if(j == str1.y)
                continue;
            if(str3.num<a[i][j])
            {
                str3.num = a[i][j];
                str3.x = i;
                str3.y = j;
            }
        }
    }
    for(int i = 0; i < n; i ++)
    {
        if(i == str1.x)
            continue;
        for(int j = 0; j < m; j ++)
        {
            if(j == str2.y)
                continue;
            if(str4.num<a[i][j])
            {
                str4.num = a[i][j];
                str4.x = i;
                str4.y = j;
            }
        }
    }
    for(int i = 0; i < n; i ++)
    {
        if(i == str3.x)
            continue;
        for(int j = 0; j < m; j ++)
        {
            if(j == str1.y)
                continue;
            if(str5.num<a[i][j])
            {
                str5.num = a[i][j];
                str5.x = i;
                str5.y = j;
            }
        }
    }
    if(str4.num>=str5.num)
    {
        xx = str3.x;
        yy = str1.y;
    }
    else
    {
        xx = str1.x;
        yy = str2.y;
    }
    cout << xx+1 << ' ' << yy+1 << endl;
    return 0;
}
耶啵家的肖兔兔 发布了35 篇原创文章 · 获赞 0 · 访问量 490 私信 关注

标签:Perfect,num,int,Gym,character,最大值,race,Ban,class
来源: https://blog.csdn.net/qq_44683599/article/details/103940642