zoj 1144 Robbery

#include <cstdlib>

#include <iostream>



using namespace std;



int a[100][100][100];

int b[100];

int bx[100], by[100];

int W, H, T;



int main(int argc, char *argv[])

{

        int n;

        int t, x1, y1, x2, y2;

        int k = 1;

        while(cin>>W>>H>>T, T)

        {

           cout<<"Robbery #"<<k++<<":"<<endl;                            

           cin>>n;

           memset(a, 0, sizeof(a));

           memset(b, 0, sizeof(b));

           for (int i = 0; i < n; i++)

           {

               cin>>t>>x1>>y1>>x2>>y2;

               for (int x=x1-1; x<x2; x++)

                 for (int  y = y1-1; y<y2; y++)

                 a[t-1][x][y] = 1;

           }

           

           for (int t = 1; t < T; t++)

             for (int x = 0; x < W; x++)

               for (int  y=0; y < H; y++)

                   if ( (x==0 || a[t-1][x-1][y])

                       && (y==0 || a[t-1][x][y-1])

                       && (a[t-1][x][y])

                       && (x == W-1 || a[t-1][x+1][y])

                       && (y == H-1 || a[t-1][x][y+1]) )

                   a[t][x][y] = 1;

                   

           bool escaped = false;

           for (int x = 0; x < W; x++)

               for (int  y=0; y < H; y++)

                 if (a[T-1][x][y]==0)

                 {

                     b[T-1]++; bx[T-1] = x; by[T-1] = y;

                 }

           if (b[T-1] == 0)escaped= true;

           for (int t = T-2; t > -1; t--)

           {

             for (int x = 0; x < W; x++)

               for (int  y=0; y < H; y++)

               {

                   if ( (x==0 || a[t+1][x-1][y])

                       && (y==0 || a[t+1][x][y-1])

                       && (a[t+1][x][y])

                       && (x == W-1 || a[t+1][x+1][y])

                       && (y == H-1 || a[t+1][x][y+1]) )

                   a[t][x][y] = 1;

                   if (a[t][x][y]==0) { b[t]++; bx[t] = x; by[t] = y; }

               }

             if (b[t]==0) { escaped=true; break; }

           }

           

           if (escaped) cout<<"The robber has escaped."<<endl;

           else

           {

               int cnt = 0;

               for (int t = 0; t < T; t++)

                 if (b[t]==1)

                 {

                   cnt++;

                   cout<<"Time step "<<t+1<<": The robber has been at "

                   <<bx[t]+1<<","<<by[t]+1<<"."<<endl;

                 }

               if (cnt == 0) cout<<"Nothing known."<<endl;

           }

           cout<<endl;

        }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值