Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.0 kB
0
Indexable
Never
#include<iostream>

using namespace std;

int N, M, SR, SC;
int fire[16][16];
int map2[16][16];
int Ex;
int visit[16][16];

int moveX[4]={-1, 0, 1, 0};
int moveY[4]={0, 1, 0, -1};

int fireNear, kc, MaxKC;

struct node{
    int r, c;
} Queue[10000];
int front, rear;
void init(){
    front = rear = -1;
}
void push(int r, int c){
    rear++;
    Queue[rear].r = r;
    Queue[rear].c = c;
}
node pop(){
    return Queue[++front];
}
bool isEmpty(){
    return front==rear;
}

//vi tri cua hugo
void backtrack(int r, int c, int time, int kc){
    return;
}

int main()
{
    int T;
    ios::sync_with_stdio(false);

    freopen("input.txt", "r", stdin);
    cin >> T;

    for(int test_case = 1; test_case <= T; ++test_case)
    {
        kc=0;
        MaxKC=0;

        cin >> N >> M >> SR >> SC;
        //reset 2 map
        for(int i=1; i<=N; i++)
            for(int j=1; j<=M; j++){
                fire[i][j] = 1000000;
                map2[i][j]=visit[i][j]=0;
            }

            //danh dau hugo
            //map1[SR][SC]=1;
            visit[SR][SC]=1;

            int k, x, y;
            //danh dau fire
            cin >> k;
            for(int i=0; i<k; i++){
                cin >> x >> y;
                push(x, y);
            }

            //danh dau lake
            cin >> k;
            for(int i=0; i<k; i++){
                cin >> x >> y;
                map1[x][y]=3;
            }

            while(!isEmpty){
                node cur = pop();
                for(int i=0; i<4; i++){
                    int newR = cur.r + moveX[i];
                    int newC = cur.c + moveY[i];
                    if(newR>=1 && newR<=N && newC>=1 && newC<=M );
                }
            }

            cout << "Case #" << test_case << endl << (MaxKC>0?MaxKC:-1) << endl;
    }
    return 0;//Your program should return 0 on normal termination.
}
Leave a Comment