#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int x1, y1, x2, y2, x0, y0, l; cin >> x1 >> y1 >> x2 >> y2; cin >> x0 >> y0 >> l; cout << fixed << setprecision(2); // <|ENG: Set 2 symbols after dot |> <|RUS: stavim 2 simvola dlia tochki |> //<|ENG: get all sides |> //<|RUS: poluchaem vse storonui |> double firstEdge = sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2)); double secondEdge = sqrt(pow(x2 - x0, 2) + pow(y2 - y0, 2)); double field = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); double ans2 = max(firstEdge, secondEdge) - l; // <|ENG: Second answer - max length |> <|RUS: Vtoroi otvet = prosto maximum do krainih tochek |> double ans1; //<|ENG: get the squares of the sides|> //<|RUS: Vosvodim v kvadrat storonui |> double a = firstEdge * firstEdge; double b = secondEdge * secondEdge; double c = field * field; //<|ENG: checking if there are obtuse angles on the side that is the pineapple field |> //<|RUS: Proverka est li typie ygli vosle toi storoni kotoraiy iavliaetsia polem c ananasami |> if (a+c < b || b+c < a) { ans1 = min(firstEdge, secondEdge) - l; } else { //<|ENG: get half the perimeter of triangle|> //<|RUS: poluchaem poly perimetr treygolnika |> double p = (firstEdge + secondEdge + field) / 2; //<|ENG: get square of triangle|> //<|RUS: poluchaem ploshad treygolnika |> double S = sqrt(p * (p - firstEdge) * (p - secondEdge) * (p - field)); //<|ENG: If the area is zero and the field with pineapples does not exist (test: 2 2 2 2 3 3 1)|> //<|RUS: Esli ploshad ravna 0 i polia c ananasami kak bu net (test: 2 2 2 2 3 3 1)|> if (S == 0 && field == 0) { ans1 = min(firstEdge, secondEdge) - l; } //<|ENG: If the area is zero and more than one side is not zero (test: -5 0 5 0 1 0 1)|> //<|RUS: Esli ploshad ravna 0 i ni odna storona ne ravna 0 (test: -5 0 5 0 1 0 1)|> else if (S == 0 && firstEdge != 0 && secondEdge != 0 && field != 0) { ans1 = 0; } else { //<|ENG: Default. We just look for the height using the formula|> //<|RUS: Obichni slychai. Prosto po formule S = a*h/2 (test: -5 0 5 0 1 0 1)|> double d = 2 * S / field; ans1 = d - l; } } //<|ENG: If, after subtracting the rope, the length becomes negative, then do 0|> //<|RUS: Esli sle vichetania verevki otvet stal menihe nylia to delayem 0|> ans1 = ans1 < 0 ? 0 : ans1; ans2 = ans2 < 0 ? 0 : ans2; //<|ENG: Next just cout "round(ans1 * 100) / 100" and "round(ans2 * 100) / 100"|> //<|RUS: Teper prosto vivedi "round(ans1 * 100) / 100" i "round(ans2 * 100) / 100"|> //!!!!!!!!!!!!!!!!!!! //cout << round(ans1 * 100) / 100 << endl; //cout << round(ans2 * 100) / 100; return 0; //<|ENG: Thanks a lot for your time here!|> //<|RUS: Spasibo chto pochitali i uia vam pomog (navernoe)|> // :) } #include <iostream> #include <cmath> using namespace std; int main(){ double x1 = 0, y1 = 0, x2 = 0, y2 = 0; double px = 0, py = 0; double length; double A = 0; double B = -1; double C = 0; double slope = 0; cin>>x1>>y1>>x2>>y2>>px>>py>>length; // get the equation of pineapple line in the form Ax + By + c = 0
if((x2 - x1) != 0){ slope = (y2 - y1) / (x2 - x1); A = slope; C = y2 - slope * x2; } if((x2 - x1) == 0){ A = 1; B = 0; C = -x1; } // now since we have Ax + By + C = 0 // we can find the shortest distance between the point and the line double short_dist = fabs(A*px + B*py + C) / sqrt(pow(A, 2) + pow(B, 2)); double dist_x1y1 = fabs(sqrt(pow(px-x1, 2) + pow(py-y1, 2))); double dist_x2y2 = fabs(sqrt(pow(px-x2, 2) + pow(py-y2, 2))); // once we have calculated the shorted distance, we need to // find out the point lying on that pineapple line which is // closest to the peg double slope_new = 0; double B_new = 0; double C_new = 0; double A_new = 0; bool status = true; if((x2 - x1) == 0){ slope_new = 0; // the other line has slope of inifinity, so this is parallel B_new = 1; A_new = 0; C_new = -py; status = false; } if((y2 - y1) == 0){ B_new = 0; A_new = 1; C_new = -px; status = false; } if(status){ slope_new = -1.0/slope; C_new = py - slope_new*px; A_new = slope_new; B_new = -1; } // calculating the point of intersection double inter_X = (-C*B_new - B*(-C_new)) / (A*B_new - B*A_new); double inter_Y = (A*(-C_new) - (-C*A_new))/(A*B_new - B*A_new); // now check whether this point lies between the given points or not ? // to do that we need to check whether both of the above calculated // coordinates lie between the range of x1, y1 and x2, y2 double min_x_coor = min(x1, x2); double min_y_coor = min(y1, y2); double max_x_coor = max(x1, x2); double max_y_coor = max(y1, y2); if(inter_X >= min_x_coor && inter_X <= max_x_coor && inter_Y >= min_y_coor && inter_Y <= max_y_coor){ // this means, the point lies on the line double one_pineapple_distance = short_dist - length; if(one_pineapple_distance <= 0){ cout<<"0.00"<<endl; } else printf("%.2f\n", one_pineapple_distance); // now to eat all the pineapples double larger_distance = max(dist_x1y1, dist_x2y2); if(larger_distance - length <= 0){ cout<<"0.00"<<endl; } else printf("%.2f\n", larger_distance - length); } // or else the perpendicuar point does not lies on the line else{ // first shorter one double shorter_distance = min(dist_x1y1, dist_x2y2); double larger_distance = max(dist_x1y1, dist_x2y2); double pineapple_1 = shorter_distance - length; if(pineapple_1 <= 0){ cout<<"0.00"<<endl; } else printf("%.2f\n", pineapple_1); double pineapple_all = larger_distance - length; if(pineapple_all <= 0){ cout<<"0.00"<<endl; } else printf("%.2f\n", pineapple_all); } return 0; } вай, как много кода) с помощью численных методов решение в 30 строк AC) С помощью точной формулы решение в 25 строк. 435 981 301 -384 -1 345 0 Correct answer: 371.78 789.08 thanks for the test found a mistake ( ˘ ³˘)♥︎ Damn, i used min(xa, xb) <= x_h <= max(xa, xb) and got WA5, then I wrote min(xa, xb) <= x_h && x_h <= max(xa, xb) and got AC #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,m,n,l,p,t,s,k; cin>>a>>b>>c>>d>>m>>n>>l; p=sqrt((a-m)*(a-m)+(b-n)*(b-n)); t=sqrt((c-m)*(c-m)+(d-n)*(d-n)); s=max(p,t); if(s>l){s-=l; } else{ s=0;} k=min(p,t); if(k<=l){ k=0; } else if(p==t){ a=(a+c)/2,b=(b+d)/2; k=sqrt((a-m)*(a-m)+(b-n)*(b-n)); if(k<=l){ k=0; } else{ k-=l; } } else{ while(abs(p-t)>.001){ if(p<t){ c=(a+c)/2,d=(b+d)/2; t=sqrt((c-m)*(c-m)+(d-n)*(d-n)); } else{ a=(a+c)/2,b=(b+d)/2; p=sqrt((a-m)*(a-m)+(b-n)*(b-n)); } } k=min(p,t); if(k<=l){ k=0; } else{ k-=l; } } cout<<fixed<<setprecision(2)<<k<<endl; cout<<fixed<<setprecision(2)<<s<<endl; } #include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <string> #include <iomanip> #include <set> using namespace std; int main() { int x1, x2, y1, y2, x3, y3, l; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> l; // h = 2/s3 в€љp(p-s3)(p-s1)(p-s2), int a = y1 - y2, b = x2 - x1, c = x1 * y2 - x2 * y1; double s1 = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), s2 = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)), s3 = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); double p = s1 + s2 + s3; p /= 2; double ans = (2 / s3 * sqrt(p * (p - s3) * (p - s1) * (p - s2))); if (max(s1, s2) * max(s1, s2) > min(s1, s2) * min(s1, s2) + s3 * s3) { ans = min(sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))); } if (s3 == 0.0) { ans = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) *(y1 - y3)); } printf("%0.2f\n", max(0.0, ans - l)); printf("%0.2f\n", max(0.0, max(sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))) - l)); } why wa#17? help pls Edited by author 23.11.2018 08:05 I tried different tasks and always got the right answer. My code is very messy I can't understand it after getting AC some months ago So probably if your code is clean and easy to read your approach is fundamentally wrong I mean, maybe there are some corner cases You can solve it using : (1) canonical straight line formula for perpendicular length ; (2) cosine theorem to know whether your perpendicular length is the answer to the first question or not; (3) Just formula for Euclidian distance and maximum function to answer the second question. type Ta=record x,y:extended; end; var a,b,c:Ta; ab,ac,bc,p,s,h,m:extended; l:extended; function max(a,b:extended):extended; begin if a-b>0 then max:=a else max:=b; end; begin readln(a.x,a.y,b.x,b.y); readln(c.x,c.y,l); ac:=sqrt(sqr(a.x-c.x)+sqr(a.y-c.y)); ab:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); bc:=sqrt(sqr(b.x-c.x)+sqr(b.y-c.y)); p:=(ab+ac+bc)/2; s:=sqrt(p*(p-ac)*(p-ab)*(p-bc)); if ab=0 then h:=ac else h:=2*s/ab; if h-l>0 then writeln(h-l:0:2) else writeln('0.00'); m:=max(ac,bc); if m-l>0 then writeln(m-l:0:2) else writeln('0.00'); end. Edited by author 03.08.2008 16:37 Try this test: -1 1 1 1 -4 -3 0 Correct answere is 5.00 6.40 I have: var ab,ca,cb,p,s1,s2,Streyg,cosA,cosB:real; Xa,Ya,Xb,Yb,Xc,Yc,L:integer; Begin Readln(Xa,Ya,Xb,Yb,Xc,Yc,L); ab:=sqrt(sqr(Xa-Xb)+sqr(Ya-Yb)); ca:=sqrt(sqr(Xa-Xc)+sqr(Ya-Yc)); cb:=sqrt(sqr(Xb-Xc)+sqr(Yb-Yc)); p:=(ab+ca+cb)/2; Streyg:=(sqrt(p*(p-ab)*(p-ca)*(p-cb)));
if ((ca>cb) and (L>=ca)) or ((ca<cb) and (L>=cb)) or ((Xa=Xb) and (Ya=Yb) and (L>=ca)) then begin s1:=0; s2:=s1; end else if (Xa=Xb) and (Ya=Yb) then begin s1:=ca; s2:=s1; end else begin if (Streyg=0) or (L>=ca) or (L>=cb) or (L>=2*Streyg/ab) then s1:=0 else begin cosA:=(ca*ca+ab*ab-cb*cb)/(2*ca*ab); cosB:=(ab*ab+cb*cb-ca*ca)/(2*ab*cb); if (cosA>=0) and (cosB>=0) then s1:=2*Streyg/ab-L else if ca>cb then s1:=cb-L else s1:=ca-L; end; if ca>cb then s2:=ca-L else s2:=cb-L; end;
writeln(s1:3:2); write(s2:3:2);
End. give me some test Why 5. Why not 4? Основание перпендикуляра не попадёт в отрезок. А по теореме Пифагора получаем для катетов 3 и 4 гипотенузу 5 import java.util.Scanner; public class Problem_1348 { public static void main(String[] args) { Scanner in=new Scanner(System.in); int ax,ay,bx,by,cx,cy,l; double ac,bc,ab,x,min,A,B,C,h; x=h=0; ax=in.nextInt(); ay=in.nextInt(); bx=in.nextInt(); by=in.nextInt(); cx=in.nextInt(); cy=in.nextInt(); l=in.nextInt();
ab= Math.sqrt( (bx-ax)*(bx-ax)+(by-ay)*(by-ay) ); ac =Math.sqrt( (cx-ax)*(cx-ax)+ (cy-ay)*(cy-ay) ); bc= Math.sqrt( (cx-bx)*(cx-bx) + (cy-by)*(cy-by) ); A=ac; B=bc; C=ab;
x=(A*A-B*B+C*C)/(2*C); h= Math.sqrt((A*A-x*x)); min=h;
if(A>B){ if(min-l<0)System.out.printf("%.2f",0.00); else System.out.printf("%.2f",min-l); System.out.println(); if(A-l<0)System.out.printf("%.2f",0.00);else System.out.printf("%.2f",A-l); }else{ if(min-l<0)System.out.printf("%.2f",0.00); else System.out.printf("%.2f",min-l); System.out.println(); if(A-l<0)System.out.printf("%.2f",0.00);else System.out.printf("%.2f",B-l); }
} } Edited by author 06.05.2014 16:57 Если основание высоты не попадает в отрезок AB, то такого расстояния не хватит What is the test #21 ? I think in this test you deal with triangle with CAB or CBA is pi/2 and you should handle this case too, not only cases when these angles more or less then pi/2, it's about precision. the two point A and B is the same point。 Yes, the test is when A=B, but in task says that AB is a segment. #include <iostream> #include <cmath> #include <stdio.h> #include <algorithm> #include <cstdio> using namespace std; double dist(int x1, int y1, int x2, int y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { double mlen,rlen,dmin,dmax,dtemp,dab_bc_ca[3]; //mlen is the perpendicular distance from C to AB //rlen is Rope Length //dab_bc_ca is length of AB, BC and CA int x1,y1,x2,y2,cx,cy; cin>>x1>>y1>>x2>>y2>>cx>>cy>>rlen; if (x1==x2 & y1==y2) //when A and B are same points { dtemp=dist(x1,y1,cx,cy); if (dtemp>rlen) dmin=dist(x1,y1,cx,cy)-rlen; else dmin=0.00; printf("%.2f\n%.2f",dmin,dmin); } else if (x1!=x2 or y1!=y2) { mlen=cx*(y1-y2)+cy*(x2-x1)+y1*(x1-x2)-x1*(y1-y2); mlen=abs(mlen)/dist(x1,y1,x2,y2); if (mlen==0)//Check the position of C, inside AB or Not? { if (dist(x1,y1,cx,cy)+dist(x2,y2,cx,cy)==dist(x1,y1,x2,y2)) printf("0.00\n"); else { dtemp=min(dist(cx,cy,x1,y1),dist(cx,cy,x2,y2)); if (rlen>=dtemp) printf("0.00\n"); else printf("%.2f\n",dtemp-rlen); } dmax=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy)); if (rlen>=dmax) cout<<"0.00"; else printf("%.2f",dmax-rlen); } else //C is outside of AB { dab_bc_ca[0]=dist(x1,y1,x2,y2); //AB dab_bc_ca[1]=dist(x2,y2,cx,cy); //BC dab_bc_ca[2]=dist(x1,y1,cx,cy); //CA sort(dab_bc_ca+0,dab_bc_ca+3); if (dab_bc_ca[2]*dab_bc_ca[2]>dab_bc_ca[1]*dab_bc_ca[1]+dab_bc_ca[0]*dab_bc_ca[0]) { //For Obtuse Angle Triangle dab_bc_ca[2]=dist(x1,y1,cx,cy); //CA dab_bc_ca[1]=dist(x2,y2,cx,cy); //CB dtemp=max(dab_bc_ca[2],dab_bc_ca[1]); //Rope length is biggest if (rlen>=dtemp) printf("0.00\n0.00"); else { dtemp=min(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy)); if (rlen>=dtemp) printf("0.00\n"); else printf("%.2f\n",dtemp-rlen); dtemp=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy)); printf("%.2f",dtemp-rlen); } } else { //for Acute angle Triangle if (rlen>=mlen) cout<<"0.00\n"<<endl; else printf("%.2f\n",mlen-rlen); dtemp=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy)); if (rlen>=dtemp) cout<<"0.00"; else printf("%.2f",dtemp-rlen); } } } return 0; } you need to write answer with two digits after point, so don't use cout! use printf("%.2f\n", ); and don't forget #include <cstdio> i've been finding this mistake for 2 days!! or u can use cout<<setprecision(2)<<fixed<<; This is my code #include <iostream> #include <stdio.h> #include <math.h> using namespace std; long n,x[201],y[201]; int main() {double xa,xb,xc,ya,yb,yc,l,a,b,c,x,h; cin>>xa>>ya>>xb>>yb>>xc>>yc>>l; b=sqrt((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya)); a=sqrt((xc-xb)*(xc-xb)+(yc-yb)*(yc-yb)); c=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); if(c!=0){ x=(c*c+b*b-a*a)/(2.0*c); h=sqrt(b*b-x*x); if(b!=0&&a!=0){ if((b*b+c*c-a*a)/(2.0*b*c)<=0) h=b; if((a*a+c*c-b*b)/(2.0*a*c)<=0) h=a;}
if(h<=l) h=0; else h=h-l;} else h=a; printf("%0.2f\n",h);
if(a>=b) {if(a<=l) h=0; else h=a-l;} else {if(b<=l) h=0; else h=b-l;} printf("%0.2f\n",h);
return 0; }
Please give me some test Попробуйте 2 2 2 2 3 3 1 Ответ: 0.41 0.41 My program gives the correct output for the test you gave, but still getting wrong answer on test#18. Any suggestions? Try this test(Sorry for my poor English): -2 -1 -4 -3 2 -1 1 correct output data: 3.00 5.32 I got accepted, but my program dont work on test: 1 1 3 3 2 2 1 correct answer - 0 0.41 my program write - 0.41 0.41 please rejudge Edited by author 21.08.2008 16:27 Edited by author 12.07.2009 05:14 Thanks, your test helps me to get AC :) Oh no WA#25! Please help me! var a1,a2,a3,h,s,aa,bb:real; a:array[1..3,1..2] of integer; i,l:integer; procedure readdata; begin readln(a[1,1],a[1,2],a[2,1],a[2,2]); readln(a[3,1],a[3,2],l); end; procedure writedata; begin if aa>=0 then writeln(aa:0:2) else writeln('0.00'); if bb>=0 then writeln(bb:0:2) else writeln('0.00'); end; function d(x1,y1,x2,y2:integer):real; begin d:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end; procedure square; var p:real; begin a1:=d(a[1,1],a[1,2],a[2,1],a[2,2]); a2:=d(a[3,1],a[3,2],a[2,1],a[2,2]); a3:=d(a[1,1],a[1,2],a[3,1],a[3,2]); p:=(a1+a2+a3)/2; s:=sqrt(p*(p-a1)*(p-a2)*(p-a2)); end; begin readdata; square; if (a[1,1]=a[2,1]) and (a[1,2]=a[2,2]) then begin aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); bb:=aa; end else begin if (a1*a1+a2*a2<a3*a3) or (a2*a2+a3*a3<a1*a1) or (a1*a1+a3*a3<a2*a2) then begin aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); if d(a[2,1],a[2,2],a[3,1],a[3,2])<aa then aa:=d(a[2,1],a[2,2],a[3,1],a[3,2]); end else begin h:=d(a[1,1],a[1,2],a[2,1],a[2,2]); aa:=s/(0.5*h); end; bb:=d(a[3,1],a[3,2],a[2,1],a[2,2]); if d(a[3,1],a[3,2],a[1,1],a[1,2])>bb then bb:=d(a[3,1],a[3,2],a[1,1],a[1,2]); end; aa:=aa-l; bb:=bb-l; writedata; end. Try this test: ---input -5 0 5 0 1 0 1 ---correct output 0.00 5.00 No, you are mistaken correct answer is 3.00 5.00 Here is explanation: * is 0 point A B C are points. <-----A----*C---B-----> ... ... = 3.00 I dont know how you got 0.00 , please explain, maybe you are right. Edited by author 16.04.2005 23:03 Distance from A up to B = 0 And to get up to point A and B a cord it is necessary to extend on 5.00 Can we discuss this problem via e-mail? akshinioi@yahoo.com Edited by author 17.04.2005 02:15 yes i know russian language. " And to get up to point A and B a cord it is necessary to extend on 5.00 " - I agree with that. But distance between A and B isnt 0, if -5+5=0 that doesnt mean that the distance equal to nil! OR explain in details how did you get this --> "Distance from A up to B = 0 " "... There is a bed of pineapples that he loves very much. The bed is a **line segment** with the ends A and B... " Point C is situated on segment AB, so there are no grounds to stretch the roap - goat anyhow can eat some pine apples, even if rope has length 0. There are infinite amount of pine apples on segment! Mail me to dkorduban[at]ukr[dot]net if you still have questions. Sorry for my English. I'm sorry, I understood my mistake. When I use linear equation for this case, i got WA#3!!! I dont know why. Please help me, how to make my program to get AC? 1) Read this nice article (in Russian): http://g6prog.narod.ru/cgeom.rar 2) Completely rewrite your program. Try to create more general program, without dozens of special cases. That's general and very useful rule (imho) for geometrical problems. For example, there is only one special case in my program - when A = B. Of course, I can send you my AC code, if you need. Thx for this test! WA #4 fixed now :) Послано Korduban [Kiev] 16 апр 2005 19:04 Try this test: ---input -5 0 5 0 1 0 1 ---correct output 0.00 5.00 Edited by author 07.11.2013 20:49 Btw, some pretty test is: 5 0 5 0 1 0 1 Correct output is 3.00 3.00 Show me test 13 please. #include <cstdio> #include <cmath> #include <algorithm> struct point { int x, y; }; double distance(const point P1, const point P2) { return sqrt((double)(P1.x - P2.x)*(P1.x - P2.x) + (double)(P1.y - P2.y)*(P1.y - P2.y)); } bool operator ==(const point P1, const point P2) { if (P1.x == P2.x && P1.y == P2.y) return 1; return 0; } int main() { point A, B, C; unsigned int L; scanf("%d%d%d%d%d%d%d", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &L); const double pi = 3.14159265; const double epsilon = 0.00000001; double alpha, beta, gamma; double a, b, c; a = distance(B, C); b = distance(A, C); c = distance(A, B); alpha = acos((b*b + c*c - a*a)/(2*b*c)); beta = acos((a*a + c*c - b*b)/(2*a*c)); gamma = acos((a*a + b*b - c*c)/(2*a*b)); if (A == B) { printf("1 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); if (L >= a) printf("0.00\n0.00\n"); else printf("%.2lf\n%.2lf\n", a - L, b - L); return 0; } if(abs(alpha + beta - pi) < epsilon) { printf("2 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = std::min(a, b); double nl2 = std::max(a, b); if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } if (abs(alpha - pi/2) < epsilon) { printf("3 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = b; double nl2 = std::max(a, b); if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } if (abs(beta - pi/2) < epsilon) { printf("4 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = a; double nl2 = std::max(a, b); if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } if(alpha > pi/2) { printf("5 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = b; double nl2 = a; if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } if(beta > pi/2) { printf("6 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = a; double nl2 = b; if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } printf("7 is working\n"); printf("a is %.2lf\nb is %.2lf\nc is %.2lf\n", a , b , c); printf("alpha is %.2lf\nbeta is %.2lf\ngamma is %.2lf\n", alpha, beta, gamma); double nl1 = b * sin(alpha); double nl2 = std::max(a, b); if (L >= nl1) printf("0.00\n"); else printf("%.2lf\n", nl1 - L); if (L >= nl2) printf("0.00\n"); else printf("%.2lf\n", nl2 - L); return 0; } Check this situations: A = B, B = C, A = C Because, if you are calculating angle between vectors with formula: cos a = (scalar mult) / (|len1| * |len2|), so if one of distance is 0 - you will get "nan" (Not A Number) = something / 0 ... Edited by author 09.11.2013 13:43 I have tested all the inputs that was given in disscutions and the output for all of them were correct. When I submit my solution, it gives WA#3. Please give me test 3. consider the case when line is vertical or horizontal and center-x or center-y is within line segment ax and bx or ay and by. |
|