Mars Canals

46 篇文章 1 订阅

1287. Mars Canals

Time limit: 1.0 second
Memory limit: 64 MB
There is a quadrate area on the Mars surface wreathed in ideal net of canals. They plot the surface into equal squares (we neglect here the surface curvature). Each side of the quadrate area plotted into  N square regions.
Archeological investigations showed that there was an ancient country Yatik in this area. The inhabitants cultivated a special grain — sir — that was a basis of their food ration. There is sir of two kinds: coarse-grained and small-grained. As a matter of fact, the end of Yatik empire started after the civil war between the fanciers of the sir sorts. But until recently noone new which of the parties won that time. The scientists look forward to guess the riddle on the grounds of the last voyage to Mars results. They found out which kind of sir was sowed the last in each square of Yatik. According to the ancient tradition sir was sowed in the sequence of squares (parallel to the north-south or east-west directions or at the angle 45° to them), one may suppose that the supporters of the party-winner made the longest sowings.

Input

The first input line contains a size of the square area —  N (1 ≤  N ≤ 1400). Then there follow  Nlines. Each of them consists of  N symbols. A letter “s” in the  i-th line and  j-th row means that in the according square region small-grained sir was sowed the last, a letter “S” means that coarse-grained sir was sowed the last. You may assume that the inhabitants of the area sowed nothing but sir. Each square region was sowed with only one sort of sir.

Output

The first line should contain a symbol “s”, if the party of small-grained sir fanciers won in the civil war. And symbol “S”, if the winners were the fanciers of the coarse-grained sir. If it’s impossible to define a winner then the first line should contain one symbol “?”. The second line should contain integer number — the maximal length of the one sort of sir sowing.

Samples

input output
3
SsS
sSs
SsS
S
3
2
sS
Ss
?
2

/** 
   DP:
   没找到翻译,自己写一个简单的题意:
   input之前都是科普,表示一群土著为了种粮食而战= =!
   只有一句话重要:
   他们种植的植物是一行,或者一列,或者与边成45度夹角的斜线,当然,会出现间断的情况(这是因为对手后来又在相同位置种了别的东西)。
   
   胜利的条件:S或者s的一方所形成的一行,或者一列,或者斜线的长度最长,如果等长,就分不出胜负
**/
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
#define maxn 1444

int Map[maxn][maxn];
int dp[maxn][maxn][4]; //45 0 90
int ans0,ans1;
int N;

void deal()//以点作为阶段进行划分,每一个点有横 竖 斜三种状态,但由于斜分两种,因此,实际上为四种状态
{
    for(int j=1; j<=N; j++)//这是三种状态的转移
        for(int k=1; k<=N; k++)
        {
            if(Map[j][k]==Map[j-1][k-1])
                dp[j][k][0]=dp[j-1][k-1][0]+1;
            else
                dp[j][k][0]=1;
            if(Map[j][k]==Map[j][k-1])
                dp[j][k][1]=dp[j][k-1][1]+1;
            else
                dp[j][k][1]=1;
            if(Map[j][k]==Map[j-1][k])
                dp[j][k][2]=dp[j-1][k][2]+1;
            else
                dp[j][k][2]=1;
            if(Map[j][k]==0)//每转移一次记录一下最大值
            {
                ans0=max(ans0,dp[j][k][0]);
                ans0=max(ans0,dp[j][k][1]);
                ans0=max(ans0,dp[j][k][2]);
            }
            else
            {
                ans1=max(ans1,dp[j][k][0]);
                ans1=max(ans1,dp[j][k][1]);
                ans1=max(ans1,dp[j][k][2]);
            }
        }
    for(int j=1; j<=N; j++)//这是第四种
        for(int k=N; k>=1; k--)
        {
             if(Map[j][k]==Map[j-1][k+1])
                dp[j][k][3]=dp[j-1][k+1][3]+1;
            else
                dp[j][k][3]=1;
            if(Map[j][k]==0)
                ans0=max(ans0,dp[j][k][3]);
            else
                ans1=max(ans1,dp[j][k][3]);
        }
}

void print()
{
    if(ans0>ans1)//最后,最大值进行比较,按照题目要求输出
        printf("s\n%d\n",ans0);
    else if(ans0<ans1)
        printf("S\n%d\n",ans1);
    else
        printf("?\n%d\n",ans0);
}

int main()
{
    scanf("%d",&N);
    memset(Map,-1,sizeof(Map));//初始化地图,-1的地方就是边界
    getchar();
    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=N; j++)
        {
            char x;
            scanf("%c",&x);
            if(x=='S')//如此构图
                Map[i][j]=1;
            else
                Map[i][j]=0;
        }
        getchar();
    }

    deal();
    print();
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值