Skip to content

Instantly share code, notes, and snippets.

@MJ111
Last active October 4, 2017 19:01
Show Gist options
  • Select an option

  • Save MJ111/fd7234a4f2a97ebe2f30268613126e69 to your computer and use it in GitHub Desktop.

Select an option

Save MJ111/fd7234a4f2a97ebe2f30268613126e69 to your computer and use it in GitHub Desktop.
Round #51
// https://csacademy.com/contest/round-51/task/manhattan-distances/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int T, a, b, c, h;
cin >> T;
for (int i = 0; i < T; i++) {
vector<int> p(3);
for (auto &it : p) {
cin >> it;
}
a = p[0], b = p[1], c = p[2];
// if sorted to incresing order a,b,c, b+c is a + 2h in triangle. a+b+c is even.
// and Triangle inequality(https://en.wikipedia.org/wiki/Triangle_inequality) should satisfied. even if it's a manhatan distance(https://en.wikipedia.org/wiki/Taxicab_geometry).
// because a,b,c forms triangle and sum of two distances is inevitably greater than one.
if (a + b < c || a + c < b || b + c < a || (a + b + c) % 2) {
cout << -1 << endl;
continue;
}
sort(p.begin(), p.end());
a = p[0], b = p[1], c = p[2];
h = (a + b - c) / 2;
cout << "0 0 " << c << " 0 " << b - h << " " << h<< endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment