ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1312. Tray

I have WA on test #5. Who can help me? (+)
Posted by Shambala 1 Oct 2005 16:11
Here it is my code:

#include <stdio.h>
#include <math.h>

#define  eps 1e-16

struct plate
{
int  id;
double  r, x, y;
} p[3], pp[3], tp;

double  h, w, temp;

double  sq(double a) {
return  a*a;}
int  possible();
void  output(int k);

int  main()
{
int  i, j, k;

scanf("%lf%lf%lf%lf%lf", &w, &h, &pp[0].r, &pp[1].r, &pp[2].r);
pp[0].id = 0;
pp[1].id = 1;
pp[2].id = 2;

for  (i = 0;  i < 3;  ++i)
for  (j = 0;  j < 3;  ++j)
for  (k = 0;  k < 3;  ++k)  if  (i != j  &&  i != k  &&  j != k) {
p[0] = pp[i];
p[1] = pp[j];
p[2] = pp[k];
if  (possible())  {
output(0);
return 0;
}
}

printf("0");
return 0;
}

////////////////////////////////////////////////////////////////

int  possible()
{
p[0].x = p[0].r;
p[0].y = p[0].r;

p[1].x = w - p[1].r;
p[1].y = p[1].r;

if  (sq(p[0].x - p[1].x) + sq(p[0].y - p[1].y)  - sq(p[0].r + p[1].r)  <  -eps) {
p[1].y = p[0].y + sqrt(sq(p[0].r + p[1].r) - sq(p[1].x - p[0].x));
if  (p[1].y + p[1].r - h > eps)
return 0;
}

p[2].x = p[2].r;
p[2].y = h - p[2].r;

if  (sq(p[0].x - p[2].x) + sq(p[0].y - p[2].y)  - sq(p[0].r + p[2].r)  <  -eps) {
p[2].x = p[0].x + sqrt(sq(p[0].r + p[2].r) - sq(p[2].y - p[0].y));
if  (p[2].x + p[2].r - w > eps)
return 0;
}

if  (sq(p[1].x - p[2].x) + sq(p[1].y - p[2].y)  - sq(p[1].r + p[2].r)  <  -eps)
return 0;

return 1;
}

void  output(int k)
{
if  (k == 1) {
double  t;
for  (k = 0;  k < 3;  ++k) {
t = p[k].x;
p[k].x = p[k].y;
p[k].y = t;
}
}

int  i, j;

for  (i = 0;  i < 3;  ++i)
for  (j = i+1;  j < 3;  ++j)
if  (p[i].id > p[j].id) {
tp = p[i];
p[i] = p[j];
p[j] = tp;
}

for  (k = 0;  k < 3;  ++k)
printf("%.4lf %.4lf ", p[k].x, p[k].y);
}
Re: I have WA on test #5. Who can help me? (+)
Posted by Ilya Rasenstein (Lyceum #40) 25 Oct 2005 23:08
It seems to me, that right solution is much more complex :(!
Re: I have WA on test #5. Who can help me? (+)
Posted by little T 9 Aug 2009 13:28
test 5:800 600 500 10 10