Moved kattis from Uni repo
This commit is contained in:
14
kattis/problems/old/boundingrobots/1.in
Normal file
14
kattis/problems/old/boundingrobots/1.in
Normal file
@ -0,0 +1,14 @@
|
||||
3 3
|
||||
1
|
||||
u 1
|
||||
4 5
|
||||
2
|
||||
u 3
|
||||
r 4
|
||||
10 10
|
||||
4
|
||||
r 30
|
||||
d 30
|
||||
l 25
|
||||
u 5
|
||||
0 0
|
71
kattis/problems/old/boundingrobots/main.c
Normal file
71
kattis/problems/old/boundingrobots/main.c
Normal file
@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
void move(char d, int s, int w, int l, int *rx, int *ry, int *x, int *y) {
|
||||
if (d == 'u') {
|
||||
*ry += s;
|
||||
if (*y + s < l) {
|
||||
*y += s;
|
||||
} else {
|
||||
*y = l-1;
|
||||
}
|
||||
} else if (d == 'd') {
|
||||
*ry -= s;
|
||||
if (*y - s >= 0) {
|
||||
*y -= s;
|
||||
} else {
|
||||
*y = 0;
|
||||
// WOW. WOW. WOW. WOW. WOW.
|
||||
}
|
||||
} else if (d == 'l') {
|
||||
*rx -= s;
|
||||
if (*x - s >= 0) {
|
||||
*x -= s;
|
||||
} else if (*x - s < 0) {
|
||||
*x = 0;
|
||||
}
|
||||
} else if (d == 'r') {
|
||||
*rx += s;
|
||||
if (*x + s < w) {
|
||||
*x += s;
|
||||
} else {
|
||||
*x = w-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int w = -1, l = -1;
|
||||
int printed = 0;
|
||||
while (1) {
|
||||
// Handle room size
|
||||
scanf("%d %d", &w, &l);
|
||||
if (w == 0 && l == 0) {
|
||||
return 0;
|
||||
}
|
||||
// Initialize actual and robot coords
|
||||
int x = 0, y = 0, rx = 0, ry = 0;
|
||||
int moves;
|
||||
// Do moves
|
||||
scanf("%d", &moves);
|
||||
for (int i=0; i<moves; i++) {
|
||||
// Take direction and steps(in meters or whatever)
|
||||
char d;
|
||||
int s;
|
||||
scanf(" %c %d", &d, &s);
|
||||
// Dear C, I hope you fucking die in a fire. What the fuck is the difference between "%c" and " %c" you pretentious ancient piece of shit. :P
|
||||
// P.S. Why the fuck is my code not working?1/1/?!?1/
|
||||
// Move
|
||||
move(d, s, w, l, &rx, &ry, &x, &y);
|
||||
}
|
||||
if (printed) {
|
||||
printf("\n");
|
||||
} else {
|
||||
printed = 1;
|
||||
}
|
||||
|
||||
printf("Robot thinks %d %d\nActually at %d %d\n", rx, ry, x, y);
|
||||
}
|
||||
return 0;
|
||||
}
|
72
kattis/problems/old/boundingrobots/main.c.orig
Normal file
72
kattis/problems/old/boundingrobots/main.c.orig
Normal file
@ -0,0 +1,72 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
|
||||
void move(char d, int s, int w, int l, int *rx, int *ry, int *x, int *y) {
|
||||
if (d == 'u') {
|
||||
*ry += s;
|
||||
if (*y + s < l) {
|
||||
*y += s;
|
||||
} else {
|
||||
*y = l-1;
|
||||
}
|
||||
} else if (d == 'd') {
|
||||
*ry -= s;
|
||||
if (*y - s >= 0) {
|
||||
*y -= s;
|
||||
} else {
|
||||
*x = 0;
|
||||
}
|
||||
} else if (d == 'l') {
|
||||
*rx -= s;
|
||||
if (*x - s >= 0) {
|
||||
*x -= s;
|
||||
} else if (*x - s < 0) {
|
||||
*x = 0;
|
||||
}
|
||||
} else if (d == 'r') {
|
||||
*rx += s;
|
||||
if (*x + s < w) {
|
||||
*x += s;
|
||||
} else {
|
||||
*x = w-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int w = -1, l = -1;
|
||||
int printed = 0;
|
||||
while (1) {
|
||||
// Handle room size
|
||||
scanf("%d %d", &w, &l);
|
||||
if (w == 0 && l == 0) {
|
||||
return 0;
|
||||
}
|
||||
// Initialize actual and robot coords
|
||||
int x = 0, y = 0, rx = 0, ry = 0;
|
||||
int moves;
|
||||
// Do moves
|
||||
scanf("%d", &moves);
|
||||
for (int i=0; i<moves; i++) {
|
||||
// Take direction and steps(in meters or whatever)
|
||||
char d;
|
||||
int s;
|
||||
scanf(" %c %d", &d, &s);
|
||||
// Dear C, I hope you fucking die in a fire. What the fuck is the difference between "%c" and " %c" you pretentious ancient piece of shit. :P
|
||||
// P.S. Why the fuck is my code not working?1/1/?!?1/
|
||||
// Move
|
||||
move(d, s, w, l, &rx, &ry, &x, &y);
|
||||
}
|
||||
if (printed) {
|
||||
printf("\n");
|
||||
} else {
|
||||
printed = 1;
|
||||
}
|
||||
|
||||
printf("Robot thinks %d %d\nActually at %d %d\n", rx, ry, x, y);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user