记录编号 114389 评测结果 AAAAAAAA
题目名称 城堡 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2014-07-29 11:52:37 内存使用 0.37 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==============
struct rooms
{
  bool wall[5];//ESWN
  int no;
  rooms()
  {
    memset(wall,0,sizeof(wall));
    no=0;
  }
}room[60][60];
//==============var declaration=================
int s[60*60];
int color=0;
 int m,n,walln;
//==============function declaration============
void fill(int row,int line);
//==============main code=======================
int main()
{  
  string FileName="castle";//程序名 
  string FloderName="USACO";//文件夹名 
  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());
#endif  
  memset(s,-1,sizeof(s));
  cin>>m>>n;//m:x   n:y
  For(i,1,n)
    For(j,1,m)
    {
      cin>>walln;
      if (walln&1) room[i][j].wall[3]=true;//West
      if (walln&2) room[i][j].wall[4]=true;//North
      if (walln&4) room[i][j].wall[1]=true;//East
      if (walln&8) room[i][j].wall[2]=true;//South
    }
  For(row,1,n)
    For(line,1,m)
      if(!room[row][line].no)
      {
        room[row][line].no=++color;
        fill(row,line);
      }
  /*
  For(row,1,n)
  {
    For(line,1,m)
      printf("%d ",room[row][line].no);
    cout<<endl;
  }
  For(i,1,color)
    printf("%d ",s[i]);
  printf("\n");
  */
  
  int maxs=0; 
  printf("%d\n",color);
  For(i,1,color)
  {
    s[i]++;
    maxs=max(maxs,s[i]);
  }
  pritnf("%d\n",maxs);
  maxs=0;
  int rr,rl;
  char pos;
  for(int nline=1;nline<=m;nline++)//西南北东 
    for(int nrow=n;nrow>=1;nrow--)
    {
      if (room[nrow][nline].wall[4]&&nrow!=1&&room[nrow][nline].no!=room[nrow-1][nline].no)//N
        if(s[room[nrow][nline].no]+s[room[nrow-1][nline].no]>maxs)
        {
          maxs=s[room[nrow][nline].no]+s[room[nrow-1][nline].no];
          pos='N';
          rr=nrow;
          rl=nline;
        } 
      if (room[nrow][nline].wall[1]&&nline!=m&&room[nrow][nline].no!=room[nrow][nline+1].no)//E
        if(s[room[nrow][nline+1].no]+s[room[nrow][nline].no]>maxs)
        {
          maxs=s[room[nrow][nline].no]+s[room[nrow][nline+1].no];
          pos='E';
          rr=nrow;
          rl=nline;
        } 
    }
  pritnf("%d\n%d %d %c",maxs,rr,rl,pos);
  return 0;
}
//================fuction code====================
void fill(int row,int line)
{
  s[room[row][line].no]++;
  if (!room[row+1][line].no&&row<n&&!room[row][line].wall[2])
  {
    room[row+1][line].no=room[row][line].no;
    fill(row+1,line);
  }
  if (!room[row-1][line].no&&row>1&&!room[row][line].wall[4])
  {
    room[row-1][line].no=room[row][line].no;
    fill(row-1,line);
  }
  if (!room[row][line+1].no&&line<m&&!room[row][line].wall[1])
  {
    room[row][line+1].no=room[row][line].no;
    fill(row,line+1);
  }
  if (!room[row][line-1].no&&line>1&&!room[row][line].wall[3])
  {
    room[row][line-1].no=room[row][line].no;
    fill(row,line-1);
  }
}