Ural 1287. Mars Canals

突然感觉Ural的难度分类有点扯. . . . . .

 dp[ i ][ j ][ k ] 表示在第K个方向上连续的个数。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>

#pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-8)
#define LL long long int
#define ULL unsigned long long int
#define _LL __int64
#define _INF 0x3f3f3f3f
#define INF 4000000
#define Mod 1000000009

using namespace std;

char s[1403][1403];
int dp[1403][1403][4];

int jx[] = { 0,-1,-1,-1};
int jy[] = {-1,-1, 0, 1};

int main()
{
    int n;

    int i,j,k;

    cin>>n;

    memset(dp,0,sizeof(dp));

    for(i = 1;i <= n; ++i)
    {

        cin>>(s[i]+1);
    }

    int M1 = -1,M2 = -1;

    for(i = 1;i <= n; ++i)
    {
        for(j = 1;j <= n; ++j)
        {
            for(k = 0;k < 4; ++k)
            {
                if(i+jx[k] == 0 || j+jy[k] == 0 || i+jx[k] == n+1 || j+jy[k] == n+1 || s[i][j] == s[i+jx[k]][j+jy[k]])
                    dp[i][j][k] = max(dp[i][j][k],dp[i+jx[k]][j+jy[k]][k]+1);
                else
                    dp[i][j][k] = 1;
                if(s[i][j] == 'S')
                {
                    M1 = max(M1,dp[i][j][k]);
                }
                else
                {
                    M2 = max(M2,dp[i][j][k]);
                }
            }

        }
    }

    if(M1 > M2)
    {
        cout<<"S"<<endl;
        cout<<M1<<endl;
    }
    else if(M1 < M2)
    {
        cout<<"s"<<endl;
        cout<<M2<<endl;
    }
    else
    {
        cout<<"?"<<endl;
        cout<<M1<<endl;
    }

    return 0;
}

你可能感兴趣的:(Ural 1287. Mars Canals)