Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created August 19, 2011 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waterlink/1157987 to your computer and use it in GitHub Desktop.
Save waterlink/1157987 to your computer and use it in GitHub Desktop.
timus Tarelki-2 1793rd problem
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
double pi = acos(-1.);
double d;
int a, b;
double r1, r2, R1, R2, h;
clock_t start = clock();
int counter = 100;
int la1, lb1, ra1, rb1;
int la2, lb2, ra2, rb2;
int main(){
freopen("input.txt", "r", stdin);
srand(78);
cin >> a >> b >> d >> r1 >> R1 >> r2 >> R2 >> h;
if (2*max(R1,R2)<=min(a,b) && pi*R1*R1+pi*R2*R2<=a*b)
{
cout<<"YES\n";
return 0;
}
double x1, y1, x2, y2, dist, disc, X, R;
if (h == 0) for (;;);
if (R1 > r1) r1 = r1 + (R1 - r1) * min(h, d) / h;
if (R2 > r2) r2 = r2 + (R2 - r2) * min(h, d) / h;
la1 = r1;
lb1 = r1;
ra1 = a - 2 * r1 + 1;
rb1 = b - 2 * r1 + 1;
la2 = r2;
lb2 = r2;
ra2 = a - 2 * r2 + 1;
rb2 = b - 2 * r2 + 1;
if (ra1 <= 0 || rb1 <= 0 || ra2 <= 0 || rb2 <= 0){
cout << "NO\n";
return 0;
}
for (; ; ){
--counter;
if (!counter){
counter = 100;
if (clock() - start >= 0.93 * CLOCKS_PER_SEC){
cout << "NO\n";
return 0;
}
}
//x1 = rand() % ra1 + la1;
//y1 = rand() % rb1 + lb1;
x1 = la1;
y1 = lb1;
//x2 = rand() % ra2 + la2;
for (x2 = la2; x2 < la2 + ra2; ++x2){
//y2 = rand() % rb2 + lb2;
X = (x2 - x1) * (x2 - x1);
R = (R1 + R2) * (R1 + R2);
disc = 4.0 * y1 * y1 - 4.0 * (X - R + y1 * y1);
if (disc < 0.0) continue;
y2 = (2.0 * y1 + sqrt(disc)) / 2.0;
//dist = hypot(x1 - x2, y1 - y2);
//if (dist < R1 + R2) continue;
if (/*x1 >= r1 && x1 <= a - r1 &&
y1 >= r1 && y1 <= b - r1 &&
x2 >= r2 && x2 <= a - r2 &&*/
y2 >= lb2 && y2 < lb2 + rb2){
cout << "YES\n";
//printf("%lf %lf %lf %lf\n", x1, y1, x2, y2);
return 0;
}
y2 = (2.0 * y1 - sqrt(disc)) / 2.0;
if (/*x1 >= r1 && x1 <= a - r1 &&
y1 >= r1 && y1 <= b - r1 &&
x2 >= r2 && x2 <= a - r2 &&*/
y2 >= lb2 && y2 < lb2 + rb2){
cout << "YES\n";
//printf("%lf %lf %lf %lf\n", x1, y1, x2, y2);
return 0;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment