/* * Given four triangles, expressed by side lengths, can we make a * square out of them? */ #include #include #include #include using namespace std ; using ll = long long ; using pt = complex ; vector> t(4, {0,0,0}) ; vector ss(3) ; vector sq = {{0,0}, {0,1}, {1,1}, {1,0}} ; vector> tp(4, vector(3)) ; const double eps = 1e-9 ; int side(pt a, pt b, pt c) { double d = (real(c) - real(b)) * (imag(a) - imag(b)) - (real(a) - real(b)) * (imag(c) - imag(b)) ; if (d < -eps) return -1 ; if (d > eps) return 1 ; return 0 ; } int sep(pt a, pt b, pt c, int ti) { int seen = side(a,b,c) ; for (int i=0; i<3; i++) if (side(a, b, tp[ti][i]) == seen) return 0 ; return 1 ; } int overlap(int t1, int t2) { for (int i=0; i<3; i++) if (sep(tp[t1][i], tp[t1][(i+1)%3], tp[t1][(i+2)%3], t2) || sep(tp[t2][i], tp[t2][(i+1)%3], tp[t2][(i+2)%3], t1)) return 0 ; return 1 ; } pt lawcos(double c, double a, double b) { const complex i = {0, 1} ; return exp(i*acos((a * a + b * b - c * c) / (2 * a * b))) ; } int insquare(complex t) { return 0 <= real(t)+eps && real(t) <= 1+eps && 0 <= imag(t)+eps && imag(t) <= 1+eps ; } int align(int ti, int ts, int nts, pt a, pt b) { tp[ti][ts] = a ; auto norm = (b - a) / abs(b-a) ; tp[ti][nts] = a + t[ti][ts] * norm ; tp[ti][3-ts-nts] = a + t[ti][nts] * norm * lawcos(t[ti][3-ts-nts], t[ti][ts], t[ti][nts]) ; return insquare(tp[ti][nts]) && insquare(tp[ti][3-ts-nts]) ; } int recur(int unused) { if (unused == 0) return 1 ; for (int ti=0; ti<4; ti++) if ((unused >> ti) & 1) { for (int ts=0; ts<3; ts++) { for (int nts=0; nts<3; nts++) { if (nts == ts) continue ; if (t[ti][ts] <= 1 + eps) { for (int ss=0; ss<4; ss++) { for (int nss=0; nss<4; nss++) { if (((nss - ss) & 3) != 1 && ((ss - nss) & 3) != 1) continue ; if (!align(ti, ts, nts, sq[ss], sq[nss])) continue ; int ok = 1 ; for (int t2=0; ok && t2<4; t2++) if (0 == ((unused >> t2) & 1)) if (overlap(ti, t2)) ok = 0 ; if (ok && recur(unused & ~(1<> t2) & 1)) if (overlap(ti, t2)) ok = 0 ; if (ok && recur(unused & ~(1<> T ; while (1) { double a = 0 ; for (auto &v: t) { for (int i=0; i<3; i++) if (!(cin>>ss[i])) exit(0) ; else v[i] = sqrt((double)ss[i]) ; a += 0.25 * sqrt(4*ss[0]*ss[1]-(ss[0]+ss[1]-ss[2])*(ss[0]+ss[1]-ss[2])); } if (abs(a-round(a)) > eps) cout << 0 << endl ; else { double s = sqrt(a) ; for (auto &v: t) for (auto &v: v) v /= s ; if (recur(15)) cout << 1 << endl ; else cout << 0 << endl ; } } }