376 - More Triangles ... THE AMBIGUOUS CASE
Moderator: Board moderators
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
376 - More Triangles ... THE AMBIGUOUS CASE
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
1 1 89.9
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
My accepted solution outputs this: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:Output:
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
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
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
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
Sorry, I'm just can't understand your question.wyvmak wrote:just then, I noticed that there's not a special correction program, does that imply side1 >= side2 in the output?
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).
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!)
Output Format!!!!:((((((((
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.
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.
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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
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


DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
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!
Sorry for posting my code but I'm really desperated 
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;
}
