文章
19
粉丝
21
获赞
5
访问
19.0k
1.最短距离
// 解公式问题
# include <iostream>
# include <math.h>
using namespace std;
int main (void){
int n;
cin >> n;
for (int i = 1; i <= n; ++i){
double x1,y1,x2,y2;
double u1,v1,u2,v2;
cin >> x1 >> y1 >> x2 >> y2;
cin >> u1 >> v1 >> u2 >> v2;
double delta_y = y1 - y2;
double delta_x = x1 - x2;
double delta_u = u1 - u2;
double delta_v = v1 - v2;
double a_2 = 2 * (delta_v * delta_v + delta_u * delta_u);
double b = 2 * (delta_y * delta_v + delta_x * delta_u);
double t = -b / a_2;
t = max((double)0,t);
double ans = (a_2 / 2) * t * t + b * t + delta_x * delta_x + delta_y * delta_y;
printf("Case %d: %.6f\n",i,sqrt(ans));
}
return 0;...
登录后发布评论
沙发