通過檢測
您的答案為: -nan -nan 正確答案為: -144.000 -643.370
為什麼會這樣 順便附上我的程式碼
#include <bits/stdc++.h>
using namespace std;
int main(){
double x1=0,y1=0,x2=0,y2=0,x3=0,y3=0;
double a=0,b=0,c=0,xm1=0,ym1=0,xm2=0,ym2=0;
double xn=0,yn=0;
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
a=(y1-y2)/(x1-x2);
b=(y2-y3)/(x2-x3);
c=(y3-y1)/(x3-x1);
if(a==b || b==c || c==a){
printf("No circumcenter.\n");
}
else if(a*b==-1){
printf("%.3lf %.3lf\n",(x3+x1)/2,(y3+y1)/2);
}
else if(c*b==-1){
printf("%.3lf %.3lf\n",(x2+x1)/2,(y2+y1)/2);
}
else if(a*c==-1){
printf("%.3lf %.3lf\n",(x3+x2)/2,(y3+y2)/2);
}
else if(a==0){
xn=(x2+x1)/2;
b=-1/b;
xm1=(x2+x3)/2;
ym1=(y2+y3)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else if(c==0){
xn=(x3+x1)/2;
b=-1/b;
xm1=(x2+x3)/2;
ym1=(y2+y3)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else if(a==0){
xn=(x2+x3)/2;
a=-1/a;
xm1=(x2+x1)/2;
ym1=(y2+y1)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else{
a=-1/a;
b=-1/b;
xm1=(x1+x2)/2;
ym1=(y1+y2)/2;
xm2=(x2+x3)/2;
ym2=(y2+y3)/2;
xn=((-a*xm1)+(b*xm2)+ym1-ym2)/(b-a);
yn=a*(xn-xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
}
return 0;
}
#0: 1% AC (2ms, 324KB)
通過檢測#1: 99% WA (line:6)
您的答案為: -nan -nan 正確答案為: -144.000 -643.370為什麼會這樣 順便附上我的程式碼
#include <bits/stdc++.h>
using namespace std;
int main(){
double x1=0,y1=0,x2=0,y2=0,x3=0,y3=0;
double a=0,b=0,c=0,xm1=0,ym1=0,xm2=0,ym2=0;
double xn=0,yn=0;
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
a=(y1-y2)/(x1-x2);
b=(y2-y3)/(x2-x3);
c=(y3-y1)/(x3-x1);
if(a==b || b==c || c==a){
printf("No circumcenter.\n");
}
else if(a*b==-1){
printf("%.3lf %.3lf\n",(x3+x1)/2,(y3+y1)/2);
}
else if(c*b==-1){
printf("%.3lf %.3lf\n",(x2+x1)/2,(y2+y1)/2);
}
else if(a*c==-1){
printf("%.3lf %.3lf\n",(x3+x2)/2,(y3+y2)/2);
}
else if(a==0){
xn=(x2+x1)/2;
b=-1/b;
xm1=(x2+x3)/2;
ym1=(y2+y3)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else if(c==0){
xn=(x3+x1)/2;
b=-1/b;
xm1=(x2+x3)/2;
ym1=(y2+y3)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else if(a==0){
xn=(x2+x3)/2;
a=-1/a;
xm1=(x2+x1)/2;
ym1=(y2+y1)/2;
yn=(b*xn)-(b*xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
else{
a=-1/a;
b=-1/b;
xm1=(x1+x2)/2;
ym1=(y1+y2)/2;
xm2=(x2+x3)/2;
ym2=(y2+y3)/2;
xn=((-a*xm1)+(b*xm2)+ym1-ym2)/(b-a);
yn=a*(xn-xm1)+ym1;
printf("%.3lf %.3lf\n",xn,yn);
}
}
return 0;
}
當b==0的時候會有問題喔,你是不是把else if(b==0)打成else if(a==0)了?