include iostream include fstream include algorithm include math double

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
double m_pi;
using namespace std;
const double eps = 1e-7;
bool between(double a, double b, double x) {
return (a - eps < x) && (x < b + eps);
}
struct angles
{
double first, second;
angles(double a, double b) : first(a), second(b)
{
if (first < 0 )
first += 2*m_pi;
if (second < 0 )
second += 2*m_pi;
if (first > 2*m_pi)
first -= 2*m_pi;
if (second > 2*m_pi)
second -= 2*m_pi;
if (first < second && second - first < m_pi ||
first > second && first - second > m_pi)
{
double t = first;
first = second;
second = t;
}
if (first > second-eps) second += 2*m_pi;
}
angles() {}
void normalize()
{
if (first >= 2*m_pi && second >= 2*m_pi)
{
first -= 2*m_pi;
second -= 2*m_pi;
}
if (first < 0)
{
first += 2*m_pi;
second += 2*m_pi;
}
}
bool fits(double x)
{
while (x - 2*m_pi > first) x-=2*m_pi;
while (x <= second+eps)
{
if (between(first, second, x)) return true;
x += 2*m_pi;
}
return false;
}
};
struct line
{
double a, b, c;
line() {};
line(double a, double b, double c) : a(a),b(b),c(c) {
normalize();
}
void normalize()
{
double d = sqrt(a*a + b*b);
a /= d; b /= d; c /= d;
}
};
ostream & operator << (ostream & o, angles const & a)
{
o << a.first <<' '<<a.second <<endl;
return o;
}
ostream & operator << (ostream & o, line const & l)
{
o << l.a <<' '<<l.b << ' ' << l.c <<endl;
return o;
}
angles getValid(line const & line, double r)
{
double sl = r*r - line.c*line.c;
if (sl < 0) return angles(0, 2*m_pi);
double l = sqrt(sl);
double ac = line.a*line.c;
double bc = line.b*line.c;
double al = line.a*l;
double bl = line.b*l;
return angles(atan2(bc+al, ac-bl), atan2(bc-al, ac+bl));
}
line getLine(double x1, double y1, double x2, double y2)
{
double a = y2-y1;
double b = x1-x2;
double c = a*x1+b*y1;
return line(a, b, c);
}
bool check(angles * an, double alpha)
{
if (alpha >= 2*m_pi) alpha -=2*m_pi;
for (int i = 0; i != 4; ++i)
if (!an[i].fits(alpha)) return false;
return true;
}
bool check(angles * an1, angles * an2, double alpha, double beta)
{
return check(an1, alpha) && check(an2, beta);
}
bool anless(angles const & a, angles const & b)
{
if (a.first < b.first) return true;
if (a.first > b.first) return false;
return a.second < b.second;
}
bool solve()
{
double a,b,c;
double a1,b1,c1;
cin >> a >> b >> c >> a1 >> b1 >> c1;
if (a > b) swap(a, b);
if (a1 > b1) swap(a1, b1);
double p = (a+b+c)/2;
double h = 2*sqrt(p*(p-a)*(p-b)*(p-c))/a;
int i = 0;
line l[4];
l[0] = line(0, 1, h/2);
l[1] = line(0, 1, -h/2);
double k = sqrt(b*b-h*h);
l[2] = getLine((a+k)/2, h/2, (a-k)/2,-h/2);
l[3] = getLine(-(a+k)/2, -h/2, -(a-k)/2,h/2);
angles an[8];
double d1 = c1/2;
double d2 = sqrt(2*a1*a1+2*b1*b1-c1*c1)/2;
if (d1 > d2) swap(d1, d2);
double alpha = acos((d1*d1+d2*d2-a1*a1)/(2*d1*d2));
int j = 0;
for (i = 0;i != 4; ++i)
{
an[i] = getValid(l[i], d1);
an[4+i] = getValid(l[i], d2);
an[4+i].first += alpha;
an[4+i].second += alpha;
an[4+i].normalize();
}
double all[17];
j = 0;
sort(an, an + 8, anless);
for (i = 0;i != 8;++i)
{
all[j++] = an[i].first;
all[j++] = an[i].second;
}
sort(all, all+16);
all[16] = all[0]+2*m_pi;
for (i = 0; i < 16;++i)
{
double x = 5.0069904867236339;
for (j = 0;j != 8;++j)
if (!an[j].fits(x)) break;
if (j == 8) return true;
for (j = 0;j != 8;++j)
if (!an[j].fits(all[i])) break;
if (j == 8) return true;
}
return false;
}
int main()
{
m_pi = atan2(0, -1);
int cases;
cin >> cases;
while (cases--)
{
if (solve()) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}