Problem Description Patrick Star find an oval.
The half of longer axes is on the x-axis with length a .
The half of shorter axes is on the y-axis with length b .
Patrick Star plan to choose a real number c randomly from [0,b] , after that, Patrick Star will get a rectangle :
1. The four vertexes of it are on the outline of the oval.
2. The two sides of it parallel to coordinate axis.
3. One of its side is y=c .
Patrick Star want to know the expectations of the rectangle's perimeter. Input The first line contain a integer T (no morn than 10), the following is T test case, for each test case :
Each line contains contains two integer a, b (0<b<a<105 ). Separated by an white space. Output For each test case output one line denotes the expectations of the rectangle's perimeter .
You should keep exactly 6 decimal digits and ignore the remain decimal digits.
It is guaranted that the 7-th decimal digit of answer wont be 0 or 9. Sample Input 1 2 1 Sample Output 8.283185 题解:主要卡精度 #include<bits/stdc++.h>
#define pi acos(-1)
using namespace std;
int main()
{
int t,n,m;
scanf("%d",&t);
while (t--){
scanf("%d%d",&n,&m);
double r=pi*n+2*m;
long long s=r*1e6;
printf("%.6lf\n",s/1e6);
}
return 0;
}
Problem Description There is a slope on the 2D plane. The lowest point of the slope is at the origin. There is a small ball falling down above the slope. Your task is to find how many times the ball has been bounced on the slope. ![](https://i-blog.csdnimg.cn/blog_migrate/f699cf776dd3361d694759b853e74b5a.jpeg)
It's guarantee that the ball will not reach the slope or ground or Y-axis with a distance of less than 1 from the origin. And the ball is elastic collision without energy loss. Gravity acceleration g=9.8m/s2 . ![](../../../data/images/C755-1012-1.jpg) Input There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 100), indicating the number of test cases.
The first line of each test case contains four integers a, b, x, y (1 ≤ a, b, -x, y ≤ 100), indicate that the slope will pass through the point(-a, b), the initial position of the ball is (x, y). Output Output the answer.
It's guarantee that the answer will not exceed 50. Sample Input 1 5 1 -5 3 Sample Output 2 解题:物理题 #include<bits/stdc++.h>
using namespace std;
const double g = 9.8;
int main()
{
int T;
double h, x, y, a, b;
cin >> T;
while(T--)
{
scanf("%lf %lf %lf %lf", &a, &b, &x, &y);
double tans = fabs(b) / fabs(a);
double sins = fabs(b) / sqrt(a*a+b*b);
double coss = fabs(a) / sqrt(a*a+b*b);
double h= fabs(x) * tans;
double v0=sqrt(2.0 * g * (y - h));
double t =2.0 * v0 / g;
double len=sqrt(x*x+h*h);
double vx=v0 * sins;
double gx=g * sins;
int cnt = 0;
while(len>= 1)
{
len-= (vx * t + 0.5 * gx * t * t);
vx+= gx * t;
cnt++;
}
printf("%d\n", cnt);
}
return 0;
} |
|