# JudgeGirl 55
## The Robots
Given pos of 2 robots, first one moves towards north at first for `n1` times, and then moves towards east for `e1` time; second one moves towards east at first and then north. Given their fuels `f1` and `f2`, each move requires 1 fuel. They will be teleported back if they go out of bound. Determine if they meet each other.
## Sample
input:
```C
7 6 2 0 9 2 100 3 5 2 7 100 // m,n,x1,y1,e1,n1,f1,x2,y2,e2,n2,f2
```
output:
```
robots explode at time 5
```
## Key
Robots will only explode if they go in to the same spot **at the same time!!**
So we move each robot first (also check out of bound) and then check if they are in the same spot.
### Loop
Notice that we will keep running until explode or there's still fuels, if both robots don't have fuels it means they didn't meet each other, so:
```C
int t = 1;
while (f1 || f2) {
// code
t++;
}
printf("no explode");
```
We also keep track of the time `int t`
### North first or east first?
As for the north east part, we can do this to each robot:
```C
int nn1 = n1; // declare a temp n1
// write north first and then east, so that when nn1 == 0 east is automatic
if (nn1) {
y1++;
nn1--;
} else if (ee1) {
x1++;
ee1--;
}
// refill both when both is 0
if (!nn1 && !ee1) {
nn1 = n1;
ee1 = e1;
}
```
For robot 2 we simply switch the `if` blocks.
## Code
```c=
#include <stdio.h>
#include <stdlib.h>
int main() {
int m,n,x1,y1,e1,n1,f1,x2,y2,e2,n2,f2;
scanf("%d %d %d %d %d %d %d %d %d %d %d %d", &m,&n,&x1,&y1,&e1,&n1,&f1,&x2,&y2,&e2,&n2,&f2);
int ee1 = e1, nn1 = n1, ee2 = e2, nn2 = n2, t = 1;
while (f1 || f2) {
if (f1) { // robot 1
if (nn1) {
y1++;
nn1--;
} else if (ee1) {
x1++;
ee1--;
}
if (!nn1 && !ee1) {
nn1 = n1;
ee1 = e1;
}
// trans
if (x1 == m) x1 = 0;
if (y1 == n) y1 = 0;
f1--;
}
if (f2) { // robot 2
if (ee2) {
x2++;
ee2--;
} else if (nn2) {
y2++;
nn2--;
}
if (!nn2 && !ee2) {
nn2 = n2;
ee2 = e2;
}
// trans
if (x2 == m) x2 = 0;
if (y2 == n) y2 = 0;
f2--;
}
if (x1 == x2 && y1 == y2) {
printf("robots explode at time %d\n", t);
return 0;
}
t++;
}
printf("robots will not explode\n");
return 0;
}
```