hdu9 1002 Just another board game

题意:一棋子初始位于(1,1),A先手,A可以横移棋子,B可以竖移棋子,或者,到某人行动的时候可以立刻终止游戏。游戏执行k轮后会结束。最终棋子停留的底下的值为最终得分,A目标是最大化,B目标是最小化。求最终答案。

思路:
在这里插入图片描述

accode:

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 9;
ll n, m, k, x, y, ans;
ll r[maxn], c[maxn];

inline void solve()
{
    ans = 0;
    scanf("%lld %lld %lld", &n, &m, &k);
    for(int i = 1; i <= n; ++i)
        r[i] = 0;
    for(int i = 1; i <= m; ++i)
        c[i] = (int)1e9;
    for(int i = 1; i <= n; ++i)        
    {
        for(int j = 1; j <= m; ++j)
        {
            scanf("%lld", &x);
            if(i == 1 && j == 1)
                y = x;
            r[i] = max(x, r[i]);
            c[j] = min(x, c[j]);
        }
            
    }
    if(k == 1)
    {
        printf("%lld\n", r[1]);
        return ;
    }
    else if(k & 1)
    {
        ans = 1e9;
        for(int i = 1; i <= n; ++i)
            ans = min(ans, r[i]);
    }
    else
    {
        for(int i = 1; i <= m; ++i)
            ans = max(ans, c[i]);
    }
    ans = max(ans, y);
    printf("%lld\n", ans);
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        solve();
    }
    return 0;
}

版权声明:本文为m0_49069293原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。