NC219656. Zipline
描述
Figure M.1: A zipline, annotated with the four variables used to describe it.
输入描述
The input starts with a line containing an integer , where . The next lines each describe a zipline configuration with four integers: , , , and . These correspond to the variables described above. The limits on their values are: , and .
输出描述
For each zipline, print a line of output with two lengths (in meters): the minimum and maximum length the cable can be while obeying the above constraints. Both lengths should have an absolute error of at most .
示例1
输入:
2 1000 100 100 20 100 20 30 2
输出:
1000.00000000 1012.71911209 100.49875621 110.07270325
C(clang11) 解法, 执行用时: 10ms, 内存消耗: 376K, 提交时间: 2021-03-27 15:17:22
#include<stdio.h> #include<math.h> #include<stdlib.h> int main(){ int n,i; scanf("%d",&n); double w,g,h,r; for(i=0;i<n;i++){ scanf("%lf%lf%lf%lf",&w,&g,&h,&r); printf("%.8lf ",sqrt(w*w+(g-h)*(g-h))); printf("%.8lf\n",sqrt((g+h-2*r)*(g+h-2*r)+w*w)); } return 0; }
C++ 解法, 执行用时: 11ms, 内存消耗: 428K, 提交时间: 2022-03-12 13:15:59
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; double a,b,c,d; while(n--){ cin>>a>>b>>c>>d; printf("%.7f %.7f\n",sqrt(a*a+(b-c)*(b-c)),sqrt((b-d+c-d)*(b-d+c-d)+a*a)); } return 0; }