Moved kattis from Uni repo
This commit is contained in:
5
kattis/problems/old/gold/1.in
Normal file
5
kattis/problems/old/gold/1.in
Normal file
@ -0,0 +1,5 @@
|
||||
7 4
|
||||
#######
|
||||
#P.GTG#
|
||||
#..TGG#
|
||||
#######
|
7
kattis/problems/old/gold/2.in
Normal file
7
kattis/problems/old/gold/2.in
Normal file
@ -0,0 +1,7 @@
|
||||
8 6
|
||||
########
|
||||
#...GTG#
|
||||
#..PG.G#
|
||||
#...G#G#
|
||||
#..TG.G#
|
||||
########
|
74
kattis/problems/old/gold/main.c
Normal file
74
kattis/problems/old/gold/main.c
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
0
|
||||
0023.0
|
||||
3.
|
||||
9.8__auto_type
|
||||
// Avoid visiting visited nodes(endless loop occurs)
|
||||
if (visited[my][mx]) {
|
||||
return ;
|
||||
}
|
||||
visited[my][mx] = true;
|
||||
|
||||
31 7
|
||||
// Stop if drafty or wall. Increment counter if gold is found.
|
||||
if (c == '#') {
|
||||
return ;
|
||||
}
|
||||
|
||||
if(c == 'T'){
|
||||
return ;
|
||||
= 0
|
||||
// printf("x: %d, y: %d, c: %c\n", mx, my, c);
|
||||
|
||||
if (c == 'G') {
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
||||
// Move (as long as we're not stepping out of bounds)
|
||||
if (mx < w) {
|
||||
move(mx+1, my, w, h); //Right
|
||||
}
|
||||
if (my < h) {
|
||||
move(mx, my+1, w, h); // Up
|
||||
}
|
||||
if (mx > 0) {
|
||||
move(mx-1, my, w, h); //Left
|
||||
}
|
||||
if (my > 0) {
|
||||
move(mx, my-1, w, h); // Down
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int w, h;
|
||||
scanf("%d %d", &w, &h);
|
||||
int px, py;
|
||||
|
||||
// Populate map
|
||||
for (int i=0; i<h; i++) {
|
||||
for (int j=0; j<w; j++) {
|
||||
scanf(" %c", &map[i][j]);
|
||||
// Set player coordinates
|
||||
if (map[i][j] == 'P') {
|
||||
py = i;
|
||||
px = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i < 100; i++) {
|
||||
for(int j=0; j < 100; j++) {
|
||||
visited[i][j] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Initiate traversal
|
||||
move(px, py, w, h);
|
||||
|
||||
// Print result
|
||||
printf("%d\n", counter);
|
||||
return 0;
|
||||
}
|
87
kattis/problems/old/gold/main.c.orig
Normal file
87
kattis/problems/old/gold/main.c.orig
Normal file
@ -0,0 +1,87 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char map[100][100];
|
||||
int visited[100][100];
|
||||
int counter = 0;
|
||||
|
||||
bool isDrafty(int x, int y) {
|
||||
// Determines whether there's a trap in the immediate vicinity of the square we're standing on
|
||||
return (map[y][x] == '.' && (map[y+1][x] == 'T' || map[y-1][x] == 'T' || map[y][x+1] == 'T' || map[y][x-1] == 'T'));
|
||||
}
|
||||
|
||||
|
||||
void move(int mx, int my, int w, int h) {
|
||||
// Moves our x, y by 1 until a wall is found or becomes drafty
|
||||
char c = map[my][mx];
|
||||
|
||||
// Avoid visiting visited nodes(endless loop occurs)
|
||||
if (visited[my][mx]) {
|
||||
return ;
|
||||
}
|
||||
visited[my][mx] = true;
|
||||
|
||||
// Stop if drafty or wall. Increment counter if gold is found.
|
||||
if (c == '#') {
|
||||
return ;
|
||||
}
|
||||
|
||||
// printf("x: %d, y: %d, c: %c\n", mx, my, c);
|
||||
|
||||
if (c == 'G') {
|
||||
counter++;
|
||||
}
|
||||
|
||||
if(c == 'T' || isDrafty(mx, my)){
|
||||
return ;
|
||||
}
|
||||
|
||||
// Move (as long as we're not stepping out of bounds)
|
||||
if (mx < w) {
|
||||
move(mx+1, my, w, h); //Right
|
||||
}
|
||||
if (my < h) {
|
||||
move(mx, my+1, w, h); // Up
|
||||
}
|
||||
if (mx > 0) {
|
||||
move(mx-1, my, w, h); //Left
|
||||
}
|
||||
if (my > 0) {
|
||||
move(mx, my-1, w, h); // Down
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int w, h;
|
||||
scanf("%d %d", &w, &h);
|
||||
int px, py;
|
||||
|
||||
// Populate map
|
||||
for (int i=0; i<h; i++) {
|
||||
for (int j=0; j<w; j++) {
|
||||
scanf(" %c", &map[i][j]);
|
||||
// Set player coordinates
|
||||
if (map[i][j] == 'P') {
|
||||
py = i;
|
||||
px = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i < 100; i++) {
|
||||
for(int j=0; j < 100; j++) {
|
||||
visited[i][j] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Initiate traversal
|
||||
move(px, py, w, h);
|
||||
|
||||
// Print result
|
||||
printf("%d\n", counter);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user