| Task: | GentleBots |
| Sender: | Hannes Ihalainen |
| Submission time: | 2017-10-31 18:50:19 +0200 |
| Language: | C++ |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.04 s | details |
| #3 | ACCEPTED | 0.05 s | details |
| #4 | ACCEPTED | 0.06 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
| #7 | ACCEPTED | 0.05 s | details |
| #8 | ACCEPTED | 0.04 s | details |
| #9 | ACCEPTED | 0.04 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y, z;
bool operator==(const P & other)const{ return(x == other.x && y == other.y &&
z == other.z);};
bool operator!=(const P & other)const{ return!(x == other.x && y == other.y &&
z == other.z);};
};
bool ok(P b1, P e1, P b2, P e2) {
if(e1 == e2) return 0;
if(b1 == e2 && b2 == e1) return 0;
return 1;
}
void print(P a, P b) {
cout<<'('<<a.x<<' '<<a.y<<' '<<a.z<<") ("<<b.x<<' '<<b.y<<' '<<b.z<<")\n";
}
int main() {
P s1, s2, g1, g2;
cin>>s1.x>>s1.y>>s1.z>>g1.x>>g1.y>>g1.z;
cin>>s2.x>>s2.y>>s2.z>>g2.x>>g2.y>>g2.z;
srand(time(0));
print(s1, s2);
while(s1 != g1 || s2 != g2) {
int fail = 1;
P e1 = s1;
P e2 = s2;
int dx = g1.x-e1.x;
dx /= max(abs(dx), 1);
int dy = g1.y-e1.y;
dy /= max(abs(dy), 1);
int dz = g1.z-e1.z;
dz /= max(abs(dz), 1);
if(dx) e1.x += dx;
else if(dy) e1.y += dy;
else e1.z += dz;
dx = g2.x-e2.x;
dx /= max(1, abs(dx));
dy = g2.y-e2.y;
dy /= max(1, abs(dy));
dz = g2.z-e2.z;
dz /= max(1, abs(dz));
if(dx) e2.x += dx;
else if(dy) e2.y += dy;
else e2.z += dz;
if(ok(s1, e1, s2, e2)) {
s1 = e1;
s2 = e2;
print(s1, s2);
fail = 0;
}
if(fail) {
// print(e1, e2);
// cout<<"LOL"<<endl;
for(int i = 0; i < 100; ++i) {
P e1 = s1;
P e2 = s2;
int q = rand()%6;
if(q == 0) e1.x++;
if(q == 1) e1.x--;
if(q == 2) e1.y++;
if(q == 3) e1.y--;
if(q == 4) e1.z++;
if(q == 5) e1.z--;
q = rand()%6;
if(q == 0) e2.x++;
if(q == 1) e2.x--;
if(q == 2) e2.y++;
if(q == 3) e2.y--;
if(q == 4) e2.z++;
if(q == 5) e2.z--;
if(ok(s1, e1, s2, e2)) {
s1 = e1;
s2 = e2;
print(s1, s2);
}
}
}
}
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 0 0 -1 0 0 1 0 0 1 0 0 -1 |
| correct output |
|---|
| (0 0 -1) (0 0 1) (0 0 0) (1 0 1) (0 0 1) (1 0 0) (0 0 1) (1 0 -1) (0 0 1) (0 0 -1) |
| user output |
|---|
| (0 0 -1) (0 0 1) (0 0 0) (1 0 1) (0 1 0) (1 0 0) (0 1 -1) (1 -1 0) (0 1 -2) (0 -1 0) ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| -124 223 38 -321 90 -17 274 -265 -332 -145 240 75 |
| correct output |
|---|
| (-124 223 38) (274 -265 -332) (-125 223 38) (273 -265 -332) (-126 223 38) (272 -265 -332) (-127 223 38) (271 -265 -332) (-128 223 38) (270 -265 -332) ... |
| user output |
|---|
| (-124 223 38) (274 -265 -332) (-125 223 38) (273 -265 -332) (-126 223 38) (272 -265 -332) (-127 223 38) (271 -265 -332) (-128 223 38) (270 -265 -332) ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 32 -397 -21 378 218 173 36 -344 365 -113 -331 372 |
| correct output |
|---|
| (32 -397 -21) (36 -344 365) (33 -397 -21) (35 -344 365) (34 -397 -21) (34 -344 365) (35 -397 -21) (33 -344 365) (36 -397 -21) (32 -344 365) ... |
| user output |
|---|
| (32 -397 -21) (36 -344 365) (33 -397 -21) (35 -344 365) (34 -397 -21) (34 -344 365) (35 -397 -21) (33 -344 365) (36 -397 -21) (32 -344 365) ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| -309 -252 245 -347 -277 -152 357 97 271 -145 68 -241 |
| correct output |
|---|
| (-309 -252 245) (357 97 271) (-310 -252 245) (356 97 271) (-311 -252 245) (355 97 271) (-312 -252 245) (354 97 271) (-313 -252 245) (353 97 271) ... |
| user output |
|---|
| (-309 -252 245) (357 97 271) (-310 -252 245) (356 97 271) (-311 -252 245) (355 97 271) (-312 -252 245) (354 97 271) (-313 -252 245) (353 97 271) ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 193 -177 210 -212 -154 -298 -258 -125 -76 -153 -204 243 |
| correct output |
|---|
| (193 -177 210) (-258 -125 -76) (192 -177 210) (-257 -125 -76) (191 -177 210) (-256 -125 -76) (190 -177 210) (-255 -125 -76) (189 -177 210) (-254 -125 -76) ... |
| user output |
|---|
| (193 -177 210) (-258 -125 -76) (192 -177 210) (-257 -125 -76) (191 -177 210) (-256 -125 -76) (190 -177 210) (-255 -125 -76) (189 -177 210) (-254 -125 -76) ... |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1 0 0 0 0 50 0 0 0 1 0 50 |
| correct output |
|---|
| (1 0 0) (0 0 0) (1 0 1) (1 0 0) (0 0 1) (1 0 1) (0 0 2) (1 0 2) (0 0 3) (1 0 3) ... |
| user output |
|---|
| (1 0 0) (0 0 0) (2 0 0) (0 -1 0) (2 0 -1) (0 -1 -1) (3 0 -1) (0 0 -1) (4 0 -1) (0 0 0) ... |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 952 0 0 952 0 0 953 0 0 951 0 0 |
| correct output |
|---|
| (952 0 0) (953 0 0) (952 0 -1) (952 0 0) (952 0 0) (951 0 0) |
| user output |
|---|
| (952 0 0) (953 0 0) (952 0 1) (954 0 0) (952 1 1) (954 0 -1) (952 1 0) (954 -1 -1) (952 1 -1) (953 -1 -1) ... |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 950 0 0 952 0 0 951 0 0 951 0 0 |
| correct output |
|---|
| (950 0 0) (951 0 0) (950 0 -1) (951 0 0) (951 0 -1) (951 0 0) (952 0 -1) (951 0 0) (952 0 0) (951 0 0) |
| user output |
|---|
| (950 0 0) (951 0 0) (950 0 1) (952 0 0) (950 1 1) (952 0 -1) (950 1 0) (952 -1 -1) (950 1 -1) (951 -1 -1) ... |
Test 9
Verdict: ACCEPTED
| input |
|---|
| -500 -500 -500 500 500 500 -500 -501 -500 500 499 500 |
| correct output |
|---|
| (-500 -500 -500) (-500 -501 -5... |
| user output |
|---|
| (-500 -500 -500) (-500 -501 -5... |
