10823 - Of Circles and Squares
Moderator: Board moderators
-
- New poster
- Posts: 21
- Joined: Sat Sep 25, 2004 3:35 am
- Location: Oaxaca de Ju
- Contact:
10823 - Of Circles and Squares
Is there any tricky thing about this problem? I do not get it accepted.
precision error..
watch out for precision error...
11 / 2 = 5.49999999999999 and not 5.50000000000000
So add necessary eps to handle this case.
11 / 2 = 5.49999999999999 and not 5.50000000000000
So add necessary eps to handle this case.
-
- New poster
- Posts: 21
- Joined: Sat Sep 25, 2004 3:35 am
- Location: Oaxaca de Ju
- Contact:
Thank you very much!
I got it accepted. You were right.
...The problem...
The color of a point is computed as the average red, average green and average blue values of the geometric objects that this point falls into. If the point is on the borderline of any of the geometric object, then its color would be black; if it falls in the empty space, the color of the point would be white.
So you do not compute it using the average formula..., regards,
Yandry.
The color of a point is computed as the average red, average green and average blue values of the geometric objects that this point falls into. If the point is on the borderline of any of the geometric object, then its color would be black; if it falls in the empty space, the color of the point would be white.
So you do not compute it using the average formula..., regards,
Yandry.
Re: precision error..
I think this can be solved by:sohel wrote:watch out for precision error...
11 / 2 = 5.49999999999999 and not 5.50000000000000
So add necessary eps to handle this case.
Code: Select all
double ar = R / inCount + 0.5;
int iar = (int)ar;
The heart and soul of my program
Can I get some i/o please ? I am tired with this.
Regards,
Suman.
Code: Select all
int onCircle(point p, point c, int len )
{
long r2 = len*len;
long d = (p.x-c.x)*(p.x-c.x) + (p.y-c.y)*(p.x-c.y);
if ( d == r2 )
return 0;
else if ( d < r2 )
return 1;
else return -1;
}
int onSquare(point p, point c, int len )
{
if ( p.x == c.x )
{
if ( (p.y >= c.y) && (p.y <= c.y + len) )
return 1;
}
if ( p.y == c.y )
{
if ( (p.x >= c.x) && (p.x <= c.x + len) )
return 1;
}
return 0;
}
int inSquare(point p, point c, int len)
{
return ( (p.x > c.x) && (p.x < c.x + len) &&
(p.y > c.y) && (p.y < c.y + len) ) ? 1 : 0;
}
Regards,
Suman.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Right on! You caught me napping.Thanks Little Joey.
Trying to get it right the simplest way possible.Any more guesses ?
Regards,
Suman.[/code]
Code: Select all
int onSquare(point p, point c, int len )
{
if ( p.x == c.x )
{
if ( (p.y >= c.y) && (p.y <= c.y + len) )
return 1;
}
if ( p.x == c.x + len )
{
if ( (p.y >= c.y) && (p.y <= c.y + len) )
return 1;
}
if ( p.y == c.y || (p.y == c.y+len) )
{
if ( (p.x >= c.x) && (p.x <= c.x + len) )
return 1;
}
if ( p.y == c.y + len )
{
if ( (p.x >= c.x) && (p.x <= c.x + len) )
return 1;
}
return 0;
}
Regards,
Suman.[/code]
Last edited by sumankar on Sat Mar 12, 2005 2:20 pm, edited 1 time in total.
Yeah, your function OnSquare is wrong, I am sure there is the mistake, try it checking the 4 sides of the square..., I mean:
bool side1, side2, side3, side4;
side1=...;
side2=...;
side3=...;
side4=...;
return side1 || side2 || side3 || side4;
sometimes partitioning makes things easier... , good luck,
Yandry.
Btw I was not accepted this ex within the 5 hours of the contest
bool side1, side2, side3, side4;
side1=...;
side2=...;
side3=...;
side4=...;
return side1 || side2 || side3 || side4;
sometimes partitioning makes things easier... , good luck,
Yandry.
Btw I was not accepted this ex within the 5 hours of the contest
How about this one :
suman
Code: Select all
int tria(point a, point b, point c)
{
return (a.x*(b.y-c.y) + b.x*(c.y-a.y) + c.x*(a.y-b.y));
}
int onSquare(point p, point c, int len )
{
point d, e, f;
d.x = c.x; d.y = c.y + len;
f.x = c.x + len; f.y = c.y;
e.x = c.x + len; e.y = c.y + len;
return ( !tria(c, p, d) ||
!tria(d, p, e) ||
!tria(e, p, f) ||
!tria(f, p, c) );
}
why make it so complex... keep it simple...
Code: Select all
int onSquare(point p, point c, int len)
{
if(inSquare(p,c,len)) return 0;
return ( (p.x >= c.x) && (p.x <= c.x + len) &&
(p.y >= c.y) && (p.y <= c.y + len) ) ? 1 : 0;
}