H - Perfect Ban (模拟)

题目链接:https://vjudge.net/problem/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

题目大意:随意删除一行一列,使矩阵剩下元素中的最大值是所有删除情况的最小情况。(哇 感觉自己的语言非常到位)

思路概括:根据贪心的思想,我们所删除的行和列应该是尽可能的包含可能多的大数,我们首先确定矩阵最大元素所在的行和列,那这个最大值我们是一定要删除的,所以下一个要寻找的应该是分别除去最大值所在行 列的次大值(如果只单纯的除去最大值找次大值的话,会忽略一种情况,就是我们的次大值和最大值在同一行同一列的情况,这样的话,我们必然是要删除最大值的行或者列的,这个次大值就没有了意义,偷偷告诉大家,这种情况就是这个题的样例8哦,我可是wa了好多发呢,qwq),我们找到次大值之后, 我们肯定是要删除的是(最大值的行,次大值的列) 或者 (次大值的行,最大值的列) 这其中的一种情况的, 那我们怎么判断删除哪种呢, 我们就可以非常直接的暴力跑这两种情况中矩阵剩下的元素哪种情况的小,这样就结束啦!!(撒花 撒花) 嘻嘻~

附上我千锤百炼的ac代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll a[1050][1050];
ll n, m;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    ll minx = -INF;
    ll x = 0, y = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin >> a[i][j];
            if(a[i][j] > minx)
            {
                minx = a[i][j];
                x = i;
                y = j;
            }
        }
    }//找出最大值的行和列



    ll maxx1 = -INF, maxx2 = -INF;
    ll xx = 0, yy = 0;
    ll xx2 = 0, yy2 = 0;
    for(int i=1; i<=n; i++)
    {
        if(i == x) continue;
        for(int j=1; j<=m; j++)
        {
            if(a[i][j] > maxx1)
            {
                maxx1 = a[i][j];
                xx = i;
                yy = j;
            }
        }
    }//不算最大值的行找出的次大值
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(j == y) continue;
            if(a[i][j] > maxx2)
            {
                maxx2 = a[i][j];
                xx2 = i;
                yy2 = j;
            }
        }
    }//不算最大值的列找出的最大值

    if(maxx1 > maxx2) xx = xx2, yy = yy2;//判断不要行还是不要列



    ll minx1 = -INF, minx2 = -INF;
    for(int i=1; i<=n; i++)
    {
        if(i == x) continue;
        for(int j=1; j<=m; j++)
        {
            if(j == yy) continue;
            if(a[i][j] > minx1)
            {
                minx1 = a[i][j];
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i == xx) continue;
        for(int j=1; j<=m; j++)
        {
            if(j == y) continue;
            if(a[i][j] > minx2)
            {
                minx2 = a[i][j];
            }
        }
    }//两种情况分别找出的次次大值
    if(minx1 > minx2)  cout << xx << ' ' << y << endl;
    else cout << x <<' ' << yy << endl;
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章