Page 1 of 1

### 376 - More Triangles ... THE AMBIGUOUS CASE

Posted: Thu Sep 12, 2002 4:04 pm
I would like to know in which order I should print the values if there are two solutions. And should I print two solutions, if the rounded values do not differ? And what should I output in this case:
1 1 89.9

Posted: Fri Sep 13, 2002 2:18 am
My accepted solution outputs this:

Code: Select all

``````Case    A      B    THETA  # of    Side   Side
#     side   side  (deg)  Triags    1      2
1   1.00   1.00  89.90     1     0.00

END OF REPORT for 1 cases``````
for 1 1 89.9 input.

You need to print values in decreasing order and AFAIR you shouldn't print two sides if rounded values isn't differ too much. Also that was a trick for me that input contains "triangles" like 7 3 0 or 5 3 180.

More I/O:
Input:

Code: Select all

`````` 1.414213 2 90.0
2.00 2.00  30.00
2.00 3.00 130.00
1.00 1.00  90.00
4.00 2.00  45.0
4.00 2.00  15.0
5 5 180
7 3 0
0 0 0``````
Output:

Code: Select all

``````Case    A      B    THETA  # of    Side   Side
#     side   side  (deg)  Triags    1      2
1   1.41   2.00  90.00     1     1.41
2   2.00   2.00  30.00     1     3.46
3   2.00   3.00 130.00     1     1.29
4   1.00   1.00  90.00     0
5   4.00   2.00  45.00     0
6   4.00   2.00  15.00     2     5.57   2.15
7   5.00   5.00 180.00     0
8   7.00   3.00   0.00     2    10.00   4.00

END OF REPORT for 8 cases``````

Posted: Fri Sep 13, 2002 7:19 pm
Thank you very much. I can handle these cases, but I still get WA. It seems I make something wrong. But I have enough of this problem, there are enough others to be solved :-)

Posted: Sat Sep 14, 2002 4:59 am
just then, I noticed that there's not a special correction program, does that imply side1 >= side2 in the output?

Posted: Sun Sep 15, 2002 5:11 pm
wyvmak wrote:just then, I noticed that there's not a special correction program, does that imply side1 >= side2 in the output?
Sorry, I'm just can't understand your question.

Also, when I wrote 'isn't differ too much' I mean that angles (I'm firstly computing angles and then sides) will be considered as different if their difference (sorry for this double diff...) less than 1e-8. So it's possible to get in answer two sides which will be looks the same. Also, pi = acos(-1).

Posted: Sun Sep 15, 2002 6:21 pm
Thanks a lot, Ivan. I had completely missed that angle=0... stupid input!! And yes, side1 should always be >= side2 in the output. I also added so that a side in the output must be at least 0.001, otherwise the triangle is considered illegal (which doesn't make sense of course since there are triangles with angle 0 and 180 in the input!)

Posted: Sun Sep 29, 2002 6:04 am
thanks to all of you. i think it's more than a year when i first tried to solve this problem.

i just wonder, how am i suppose to know the output format in such a way. how am i suppose to handle 0 and 180, if not your hints. or it's just a good proof that i'm not clever enough for ACM?

Posted: Sun Sep 29, 2002 11:58 pm
Be assured that the problem statements in the ACM nowadays are a lot better and don't have these kind of ugly statementts. At least that's the case in the european regionals. The input and output format are usually very simple and trivial and there are almost never any dirty test cases.

### Output Format!!!!:((((((((

Posted: Tue Nov 05, 2002 3:19 pm
Can any one tell me exactly wats the ouput format??
I mean how many gaps between the words ?
Or wats the value for a, b in print (%a.blf)...

I think it will be easier if someone can give me printing part of his/her code..

Thanks
Light.

Posted: Thu Apr 24, 2003 8:35 am
Hmmm
Two sentence from me:
1. I don't care about small differences in sides - maybe my algorithm avoid it ? I don't know, I got it from book with math tables
2. Thanks for cases with angle 0.00 ) That was nice case

DM

Posted: Mon Apr 24, 2006 3:06 pm
After a 20+ WAs have decided post my code, I handle OK all the cases from this board. Could anyone say me any trick or say me what is my fault?
Thanks!

Code: Select all

``````#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;

/* I works with some parameters from the posts of this topic */
#define PI acos(-1)
#define EPS 1e-4
#define EPS2 1e-8
#define EPS3 0

/* I works with cosine law */
int solve(double aa, double bb, double AA, double &dd1, double &dd2)
{
double a=1;
double b=-(2*bb*cos((AA*PI)/180.0));
double c=bb*bb-aa*aa;
if (b*b-4*a*c<0) return 0;
dd1=(-b-sqrt(b*b-4*a*c))/(2*a);
dd2=(-b+sqrt(b*b-4*a*c))/(2*a);
if (dd1<EPS) dd1=0;
if (dd2<EPS) dd2=0;
if (dd1==0) dd1=dd2;
if (fabs(dd1-dd2)<EPS2) dd2=0;
return ((dd1!=0) + (dd2!=0));
}

int main ()
{
cout << "Case    A      B    THETA  # of    Side   Side\n";
cout << "#     side   side  (deg)  Triags    1      2\n";
int caso=1;
double a,b,A,d1,d2;
while (cin >> a >> b >> A && (a!=0 || b!=0 || A!=0))
{
/*assert(a>EPS && b>EPS), assert(a>0 && b>0), assert(A>=0 && A<=180);
if (A==0)
{printf("%4d%6.2lf%7.2lf%7.2lf%6d%9.2lf%7.2lf\n",caso++,a,b,A,2,a+b,abs(a-b)); continue;}
if (A==180)
{printf("%4d%6.2lf%7.2lf%7.2lf%6d\n",caso++,a,b,A,0); continue;}
*/

if (solve(b,a,A,d1,d2)==2)
printf("%4d%6.2lf%7.2lf%7.2lf%6d%9.2lf%7.2lf\n",caso++,a,b,A,2,d2,d1);
else if (solve(b,a,A,d1,d2)==1)
printf("%4d%6.2lf%7.2lf%7.2lf%6d%9.2lf%\n",caso++,a,b,A,1,d1);
else printf("%4d%6.2lf%7.2lf%7.2lf%6d\n",caso++,a,b,A,0);
}
cout << "\nEND OF REPORT for " << caso-1 << " cases\n";
return 0;
}``````
Sorry for posting my code but I'm really desperated