记录编号 118370 评测结果 AAAAAAAAAA
题目名称 Blue Mary的战役地图 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.029 s
提交时间 2014-09-06 14:50:19 内存使用 0.34 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7ffffff;
//==============struct declaration==============

//==============var declaration=================
const int MAXN=55;
int n,low,high,mid;
int map1[MAXN][MAXN],map2[MAXN][MAXN];
set <Uint> exist;
//==============function declaration============
Uint hash(int (*map)[MAXN],int r,int c,int l);
//==============main code=======================
int main()
{  
  string FileName="campaign";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  scanf("%d",&n);
  For(i,1,n)
    For(j,1,n)
      scanf("%d",&map1[i][j]);
  For(i,1,n)
    For(j,1,n)
      scanf("%d",&map2[i][j]);
  low=0;high=n;
  while (low<high)
  {
    exist.clear();
    mid=(1+low+high)>>1;
    for(int row=1;row<=n-mid+1;row++)
      for(int line=1;line<=n-mid+1;line++)
      {
        Uint hash_value=hash(map1,row,line,mid);
        exist.insert(hash_value);
      }
    bool suc=false;
    for(int row=1;row<=n-mid+1;row++)
      for(int line=1;line<=n-mid+1;line++)
      {
        Uint hash_value=hash(map2,row,line,mid);
        if (exist.count(hash_value))
        {
           suc=true;
           goto OUT__;                 
        }
      }
    OUT__:
    if (suc)
      low=mid;
    else
      high=mid-1;
  }
  pritnf("%d\n",low);
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif    
  return 0;
}
//================fuction code====================
Uint hash(int (*map)[MAXN],int r,int c,int l)
{
   Uint MUL=1000000007;
   Uint sum=0;
   For(i,r,r+l-1)
     For(j,c,c+l-1)
       sum=sum*MUL+map[i][j];
   return sum;
}