提交时间:2022-10-15 11:25:41
运行 ID: 60326
#include<bits/stdc++.h> using namespace std; inline int read(){ char c = getchar(); int w = 1 , s = 0; while(!isdigit(c)){ if(c == '-') w = -1; c = getchar(); } while(isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48) , c = getchar(); return w * s; } struct line { double k , c; }; inline double squa(double x){ return x * x; } inline double calc_dis(double x_1 , double y_1 , double x_2 , double y_2){ return sqrt(squa(x_2 - x_1) + squa(y_2 - y_1)); } inline line calc_line(double x_1 , double y_1 , double x_2 , double y_2){ line l; l.k = (y_2 - y_1) / (x_2 - x_1); l.c = y_2 - l.k * x_2; return l; } int main(){ // freopen("S1.in" , "r" , stdin); // freopen("S1.out" , "w" , stdout); int t = read(); while(t--){ double x_1 , y_1 , x_2 , y_2 , x_3 , y_3 , r; scanf("%lf %lf %lf %lf %lf %lf %lf" , &x_1 , &y_1 , &x_2 , &y_2 , &x_3 , &y_3 , &r); double ans1 , ans2; if(x_1 == x_2) ans1 = abs(x_3 - x_1) - r; else{ //第一个距离 //计算直线,然后点到直线的距离再减去圆的半径 line l = calc_line(x_1 , y_1 , x_2 , y_2); ans1 = abs(((l.k * x_3 - y_3 + l.c) / sqrt(squa(l.k) + 1))) - r; } //第二个距离 ans2 = max(calc_dis(x_1 , y_1 , x_3 , y_3) , calc_dis(x_2 , y_2 , x_3 , y_3)) + r; printf("%.2f %.2f\n" , ans1 , ans2); } return 0; }