Skip to content

Instantly share code, notes, and snippets.

@h3ct0rjs
Created May 6, 2016 19:00
Show Gist options
  • Save h3ct0rjs/bb6447f2bbf3f855f1a4af7f51c76022 to your computer and use it in GitHub Desktop.
Save h3ct0rjs/bb6447f2bbf3f855f1a4af7f51c76022 to your computer and use it in GitHub Desktop.
1337 Leet maze.
4
4 5 2
..#..
.C#C.
##..#
..C#C
1 1
4 1
6 2 5
##
..
##
##
.#
.#
2 2
5 1
6 1
5 1
5 1
8 8 8
CCC#CC..
CCC.C..C
#....CC.
.CC..#C.
#C.....C
C.CC..CC
.CC....#
CCC##CC.
6 5
4 4
6 5
6 6
6 2
8 8
2 6
6 5
4 5 2
..#..
.C#C.
##..#
..C#C
1 1
4 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char kingdom[25][25];
char kingdom_cpy[25][25];
typedef struct
{
int coor_x;
int coor_y;
} cells;
int main()
{
int t, N, M, Q, idCase, idCol, idRow, CoorX, CoorY;
int idHead, idTail, totalCells, L,k;
char casilla, line[25];
cells queue[405], cell;
scanf("%d", &t);
for(idCase=1; idCase<=t; idCase++)
{
idHead = 1;
idTail = 1;
totalCells = 0;
scanf("%d %d %d", &M, &N, &Q);
for(idRow=1; idRow<=M; idRow++)
{
scanf("%s", line);
for(idCol=1; idCol<=N; idCol++)
{
kingdom[idCol][idRow] = line[idCol-1];
}
}
printf("Case %d: \n", idCase);
while(Q!=0)
{
Q--;
for(idRow=1; idRow<=M; idRow++)
{
for(idCol=1; idCol<=N; idCol++)
{
kingdom_cpy[idCol][idRow] = kingdom[idCol][idRow];
}
}
k=0;
scanf("%d %d", &CoorX, &CoorY );
queue[idTail].coor_x = CoorX;
queue[idTail].coor_y = CoorY;
idTail++;
L=67;
while(idHead < idTail)
{
cell = queue[idHead];
idHead++;
if(((cell.coor_x - 1) >= 1) &&
(kingdom_cpy[cell.coor_x - 1][cell.coor_y] == '.'))
{
kingdom_cpy[cell.coor_x - 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x - 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
}
if(((cell.coor_x - 1) >= 1) &&
(kingdom_cpy[cell.coor_x - 1][cell.coor_y] == L))
{
kingdom_cpy[cell.coor_x - 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x - 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
k++;
}
if(((cell.coor_x + 1) <= N) &&
(kingdom_cpy[cell.coor_x + 1][cell.coor_y] == '.'))
{
kingdom_cpy[cell.coor_x + 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x + 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
}
if(((cell.coor_x + 1) <= N) &&
(kingdom_cpy[cell.coor_x + 1][cell.coor_y] == L))
{
kingdom_cpy[cell.coor_x + 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x + 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
k++;
}
if(((cell.coor_y - 1) >= 1) &&
(kingdom_cpy[cell.coor_x][cell.coor_y - 1] == '.'))
{
kingdom_cpy[cell.coor_x][cell.coor_y - 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y - 1;
idTail++;
}
if(((cell.coor_y - 1) >= 1) &&
(kingdom_cpy[cell.coor_x][cell.coor_y - 1] == L))
{
kingdom_cpy[cell.coor_x][cell.coor_y - 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y - 1;
idTail++;
k++;
}
if(((cell.coor_y + 1) <= M) &&
(kingdom_cpy[cell.coor_x][cell.coor_y + 1] == '.'))
{
kingdom_cpy[cell.coor_x][cell.coor_y + 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y + 1;
idTail++;
}
if(((cell.coor_y + 1) <= M) &&
(kingdom_cpy[cell.coor_x][cell.coor_y + 1] == L))
{
kingdom_cpy[cell.coor_x][cell.coor_y + 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y + 1;
idTail++;
k++;
}
}
printf("%d %d\n", k,Q);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Data Structure code.
using namespace std;
//Function Prototype.
int solve(int x, int y); //Solve your fucking problem 1337 leet maze
void fillmap(char kingdom[25][25]); //Fill the map of the kingdom
char kingdom[25][25], kingdom_cpy[25][25],casilla, line[25];
int T, N, M, Q, idCase, idCol, idRow, CoorX, CoorY,idHead, idTail, totalCells,L,k; //please name this fucking thing
//we really need to care what's the real porpouse of the var.
typedef struct{
int coor_x;
int coor_y;
}cells; //simple structure..
cells queue[405], cell;
int main(){
int c=1;
scanf("%d", &T);
while(T--){
scanf("%d %d %d", &M, &N, &Q);
fillmap(kingdom); //fill the kingdom... xD
//printmap(kingdom); //For Debug Porpuose
printf("Case %d:\n",c); //In what number of Case we are?...
while(Q--){ //Meanwhile thereis a Query
scanf("%d %d", &CoorX, &CoorY ); //read the query
printf("%d\n",solve(CoorX,CoorY)); //printf
}
c++;
}
}
void fillmap(char kingdom[25][25]){
for(idRow=1; idRow<=M; idRow++)
{
scanf("%s", line);
for(idCol=1; idCol<=N; idCol++)
{
kingdom[idCol][idRow] = line[idCol-1];
}
}
}
int solve(int x, int y){
for(idRow=1; idRow<=M; idRow++){ //create a fucking copy of the string
for(idCol=1; idCol<=N; idCol++){
kingdom_cpy[idCol][idRow] = kingdom[idCol][idRow];
}
}
queue[idTail].coor_x = x;
queue[idTail].coor_y = y;
idTail++;
L=67;
while(idHead < idTail){
cell = queue[idHead];
idHead++;
if(((cell.coor_x - 1) >= 1) &&
(kingdom_cpy[cell.coor_x - 1][cell.coor_y] == '.'))
{
kingdom_cpy[cell.coor_x - 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x - 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
}
if(((cell.coor_x - 1) >= 1) &&
(kingdom_cpy[cell.coor_x - 1][cell.coor_y] == L))
{
kingdom_cpy[cell.coor_x - 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x - 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
k++;
}
if(((cell.coor_x + 1) <= N) &&
(kingdom_cpy[cell.coor_x + 1][cell.coor_y] == '.'))
{
kingdom_cpy[cell.coor_x + 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x + 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
}
if(((cell.coor_x + 1) <= N) &&
(kingdom_cpy[cell.coor_x + 1][cell.coor_y] == L))
{
kingdom_cpy[cell.coor_x + 1][cell.coor_y] = '#';
queue[idTail].coor_x = cell.coor_x + 1;
queue[idTail].coor_y = cell.coor_y;
idTail++;
k++;
}
if(((cell.coor_y - 1) >= 1) &&
(kingdom_cpy[cell.coor_x][cell.coor_y - 1] == '.'))
{
kingdom_cpy[cell.coor_x][cell.coor_y - 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y - 1;
idTail++;
}
if(((cell.coor_y - 1) >= 1) &&
(kingdom_cpy[cell.coor_x][cell.coor_y - 1] == L))
{
kingdom_cpy[cell.coor_x][cell.coor_y - 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y - 1;
idTail++;
k++;
}
if(((cell.coor_y + 1) <= M) &&
(kingdom_cpy[cell.coor_x][cell.coor_y + 1] == '.'))
{
kingdom_cpy[cell.coor_x][cell.coor_y + 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y + 1;
idTail++;
}
if(((cell.coor_y + 1) <= M) &&
(kingdom_cpy[cell.coor_x][cell.coor_y + 1] == L))
{
kingdom_cpy[cell.coor_x][cell.coor_y + 1] = '#';
queue[idTail].coor_x = cell.coor_x;
queue[idTail].coor_y = cell.coor_y + 1;
idTail++;
k++; //this is necesary '
}
}
return(k);
}
@h3ct0rjs
Copy link
Author

h3ct0rjs commented May 6, 2016

[email protected]

They just need to fix their implementation, exist one thing that is increasing the k value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment