记录编号 123809 评测结果 AAAAAAAAAA
题目名称 [USACO Dec08] 花园栅栏 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.023 s
提交时间 2014-09-28 22:41:00 内存使用 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;
const double eps=1e-6;
//==============struct declaration==============

//==============var declaration=================
const int MAXN=110;
bool Wall[MAXN][MAXN][4];
int x,y,dist,n,ans=0;
char cmd;
bool vis[MAXN][MAXN];
int mvx[]={0,1,0,-1};
int mvy[]={1,0,-1,0};
//==============function declaration============
void move();
void floodfill(int x,int y);
//==============main code=======================
int main()
{  
  string FileName="fence";//程序名 
  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    
  ios::sync_with_stdio(false);
  cin>>x>>y>>n;
  For(i,1,n){
    cin>>cmd>>dist;
    move();
  }
  For(i,0,100)
    For(j,0,100)
      if (!vis[i][j])
        floodfill(i,j);
  cout<<ans<<endl;
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)*1000/(CLOCKS_PER_SEC)<<" Ms"<<endl;
#endif    
  return 0;
}
//================fuction code====================
void move()
{
   if (cmd=='N'){
     for(int i=0;i<=dist-1&&i+y<=100;i++){
       if (x!=0)
         Wall[x-1][y+i][1]=Wall[x][y+i][3]=true;
       else
         Wall[x][y+i][3]=true;
     }
     y+=dist;
   }
   else if (cmd=='S'){
     for(int i=1;i<=dist&&y-i<=100;i++){
       if (x!=0)
         Wall[x-1][y-i][1]=Wall[x][y-i][3]=true;
       else
         Wall[x][y-i][3]=true;
     }
     y-=dist;
   }
   else if (cmd=='E'){
     for(int i=0;i<=dist-1&&x+i<=100;i++){
       if (y!=0)
         Wall[x+i][y-1][0]=Wall[x+i][y][2]=true;
       else
         Wall[x+i][y][2]=true;
     }
     x+=dist;
   }
   else if (cmd=='W'){   
     for(int i=1;i<=dist&&x-i>=0;i++){
       if (y!=0)
         Wall[x-i][y-1][0]=Wall[x-i][y][2]=true;
       else
         Wall[x-i][y][2]=true;
     }
     x-=dist;
   }
}
void floodfill(int x,int y)
{
   bool out=false;
   int cnt=0;
   queue <int> X;
   queue <int> Y;
   vis[x][y]=true;
   X.push(x);Y.push(y);
   while (!X.empty()){
     int xx=X.front(),yy=Y.front();
     X.pop();Y.pop();
     if (xx>100||yy>100||xx<0||yy<0){
       out=true;
       continue;
     }
     cnt++;
     For(i,0,3)
       if (!Wall[xx][yy][i]){
         int xxx=xx+mvx[i];
         int yyy=yy+mvy[i];
         if (xxx<0||yyy<0){
            out=true;
            continue;
         }
         if (!vis[xxx][yyy])
           X.push(xxx),Y.push(yyy);
         vis[xxx][yyy]=true;
       }
   }
   if (!out)
     ans+=cnt;
}