I spent too much time on this problem. But still WA #28. Help me!!
Can anyone tell me my mistake. Here is my code. Thanks
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
//#include <conio.h>
using namespace std;
#define oo 1000000000
#define fi first
#define se second
#define sqr(a) ((a)*(a))
#define FR(i,n) for (int i = 0; i < (n); i++)
#define DN(i,a) for(int i = (a)-1; i >= 0; i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define DOWN(i,a,b) for(int i = (a); i >= (b); i--)
#define FORV(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end(); i++)
typedef pair<int, int> PII;
typedef vector<int> VI;
double kc(double x1, double y1, double x2, double y2) {
return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
int main () {
double a, b, d, r11, r12, r21, r22, h;
cin >> a >> b >> d;
cin >> r11 >> r12 >> r21 >> r22 >> h;
if (2 * max(r21, r11) > min(a, b)) {
cout << "NO" << endl;
return 0;
}
double x1 = r11, y1 = r11;
double x2 = a - r21, y2 = b - r21;
if (kc(x1, y1, x2, y2) < r11 + r21) {
cout << "NO" << endl;
return 0;
}
if (d >= h) {
if (2 * max(r12, r22) > min(a, b)) {
cout << "NO" << endl;
return 0;
}
double x1 = r12, y1 = r12;
double x2 = a - r22, y2 = b - r22;
if (kc(x1, y1, x2, y2) < r12 + r22) {
cout << "NO" << endl;
return 0;
}
}
if (d < h) {
double r1m = d * (r12 - r11) / h + r11;
double r2m = d * (r22 - r21) / h + r21;
if (2 * max(r1m, r2m) > min(a, b)) {
cout << "NO" << endl;
return 0;
}
double x1 = r1m, y1 = r1m;
double x2 = a - r2m, y2 = b - r2m;
if (kc(x1, y1, x2, y2) < r1m + r2m) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}