Page 1 of 2

10991 - Region

Posted: Sun Feb 12, 2006 12:09 pm
by TISARKER
I am getting wrong answer.
My output does not match for sample input.
For each test case, my procedure is.
1.Read R1,R2,R3.
Make a triange by center of given 3 circles.
2.
Evaluate 3 sides of the triangle.
s12=R1+R2; s13=R1+R3; s23=R2+R3;
Finf out Area of the triangle.
Suppose Area is A.
3.
Find out angle of each point of the triangle.
A1=asin((2*A)/(s12*s13))
A2=Same formulae.
A3=Same formulae.
Convert A1,A2,A3 into degree from radian.
4.Find out area of part of each circle which is inside triangle.
v1=(pi*R1*R1*A1)/360
v2=same process
v3=same process
5.Sum=v1+v2+v3.
5.result=A-sum.
6.Display result with 6 decimal place.

Code: Select all

Delete Code

Posted: Sun Feb 12, 2006 12:26 pm
by misof
On the first glance, the way you compute the angles will fail for triangles where one of the angles is larger than 90 degrees. Note that from the sine of the angle you can't tell whether it is x or (180 degrees-x). Use cosine instead.

Also, your currently posted code doesn't compile under my gcc.

Posted: Sun Feb 12, 2006 1:43 pm
by TISARKER
misof wrote:On the first glance, the way you compute the angles will fail for triangles where one of the angles is larger than 90 degrees. Note that from the sine of the angle you can't tell whether it is x or (180 degrees-x). Use cosine instead.
I convert sina into cosa
I above code is modifided
But not getting inprovement :cry:
Please help me.

Posted: Sun Feb 12, 2006 1:55 pm
by TISARKER
Sorry for double posting :P

Posted: Sun Feb 12, 2006 2:01 pm
by wook
Use The Cosine Law(Theorem).

a^2 = b^2 + c^2 - 2bc cosA

Posted: Sun Feb 12, 2006 2:03 pm
by misof
You missed the point. You need the exact value of the cosine, including its sign. For angles between 90 and 180 degrees the cosine is negative, and this is how acos() can tell that the original angle is obtuse. When you compute the cosine from the sine, you won't get the correct sign.

see: http://mathworld.wolfram.com/LawofCosines.html

Posted: Sun Feb 12, 2006 4:31 pm
by TISARKER
Thanks misof :D
Thanks wook :D

Posted: Mon Feb 13, 2006 9:12 pm
by ayon
i got ac using sine formula as tisarker did first. there may be at most one angle greater than 90 degrees. so i checked if the angle is greater than 90 degrees, and if found i subtracted the angle from 180 degrees.

Code: Select all

      A = asin(2*del/b/c);
      B = asin(2*del/a/c);
      C = asin(2*del/a/b);
      if(b*b+c*c < a*a)  // A > 90 degrees
      	A = pi - A;
      else if(a*a+b*b < c*c)  // C > 90 degrees
      	C = pi - C;
      else if(c*c+a*a < b*b)  // B > 90 degrees
      	B = pi - B;
here del is the area of the triangle, and it is a good idea never to use degrees instead of radians.

Posted: Mon Feb 13, 2006 9:14 pm
by ayon
i got ac using sine formula as tisarker did first. there may be at most one angle greater than 90 degrees. so i checked if the angle is greater than 90 degrees, and if found i subtracted the angle from 180 degrees.

Code: Select all

      A = asin(2*del/b/c);
      B = asin(2*del/a/c);
      C = asin(2*del/a/b);
      if(b*b+c*c < a*a)
      	A = pi - A;
      else if(a*a+b*b < c*c)
      	C = pi - C;
      else if(c*c+a*a < b*b)
      	B = pi - B;
here del is the area of the triangle, and it is a good idea never to use degrees instead of radians.

Posted: Mon Feb 13, 2006 10:12 pm
by sclo
I still think using cosine formula should be preferred, although sine formula with additional checking can be used. During actual contests, it's easy to forget checking the conditions for the sine formula.

Posted: Tue Feb 14, 2006 7:21 am
by sumankar
How come no one has ever bothered about the apparent discrepancy in
the problem description?
Prob desctiption:Output

Code: Select all

For each line of input, generate one line of output containing the area of G rounded to six decimal digits after the decimal point. Floating-point errors will be ignored by special judge program.
and the sample i/o
Input

Code: Select all

2
5.70 1.00 7.89
478.61 759.84 28.36
Output

Code: Select all

1.2243
2361.0058
with only 4 places of decimal. My AC prog has more than two zeroes
following each of these two output. This cost me a WA!

Posted: Tue Feb 14, 2006 8:07 am
by wook
I have been bothered, too.
My AC Program outputs

Code: Select all

1.224323
2361.005761
In fact, at first, my output format was rounded to four decimal digits after the decimal point,

i.e.

Code: Select all

if(-EPS <= area && area <= EPS)
	printf("0.000000\n", area);
else printf("%.4lf\n", area);
This gave me WA.
I didn't read the problem description CAREFULLY.


but, instead, the output format like

Code: Select all

if(-EPS <= area && area <= EPS)
	printf("0.000000\n", area);
else printf("%.6lf\n", area);
gave me ACCEPTED.
what a strange happening!

well, I can't understand why the example of output is of only 4 places of decimal.
It should be changed, I think.

Posted: Tue Feb 14, 2006 8:24 am
by Observer
Well you might call it a "discrepancy", but I think if the problem statement has made that clear and you miss it, you have got no one to blame.

Still, it would be good if the sample I/O is changed.

Posted: Tue Feb 14, 2006 10:04 am
by sumankar
Observer wrote:Well you might call it a "discrepancy",
... as in discordance, disagreement;
Observer wrote: but I think if the problem statement has made that clear and you miss it, you have got no one to blame.
0. I was not blaming some[one|thing], but was musing aloud.
1. The problem statement body & sample i/o make one whole: at least to me, and I don't
see any reason to trust one figure more than a host of others ;)
2. I agree that setting problems is a tough thing, which is why I didn't bother to write about
this issue to the contest clarificator(s) during the contest. However, I was hoping, by now
a correction's due.

10991 - Region

Posted: Mon Mar 06, 2006 3:26 am
by Roby
I just want to know if the cosine of sine theorem valid for this problem... I mean, are these theorem can be used to solve this problem? Here are the theorem page: http://digilib.brawijaya.ac.id/virtual_ ... 203-1e.htm

Thanx in advance :)