天天看点

杭电9-Just another board game

​​传送门​​

杭电9-Just another board game

题意:

思路:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
#include<vector>
using namespace std;
#define ll long long
ll maxx_n[100010];
ll maxx_m[100010];

int main()
{
  int t;
  cin>>t;
  while(t--)
  {
    int n,m;
    ll k;
    ll s = 0;
    scanf("%d%d%lld",&n,&m,&k);
    memset(maxx_n,0,sizeof(maxx_n));
    memset(maxx_m,0x3f3f3f3f,sizeof(maxx_m));
    for(int i = 0; i < n; i++)
    {
      for(int j = 0; j < m; j++)
      {
        ll op;
        scanf("%lld",&op);
        if(i == 0 && j == 0)s = op;
        maxx_n[i] = max(maxx_n[i], op);
        maxx_m[j] = min(maxx_m[j], op);
      }
    }
    if(k == 1)
    {
      printf("%lld\n", maxx_n[0]);
    }
    else if(k == 2)
    {
      ll ans = 0;
      for(int i = 0; i < m; i++)ans = max(maxx_m[i], ans);
      printf("%lld\n",max(ans, s));
    }
    else if(k%2)
    {
      ll ans = 0x3f3f3f3f;
      for(int i = 0; i < n; i++)ans = min(ans, maxx_n[i]);
      printf("%lld\n",max(ans, s));
    }
    else if(k%2==0)
    {
      ll ans = 0;
      for(int i = 0; i < m; i++)ans = max(maxx_m[i], ans);
      printf("%lld\n",max(ans, s));
    }
  }
}