题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6373
题意:一道简单的高中物理题,问你小球一共与斜面碰撞了几次?
思路:
对直角坐标系进行变换,成沿斜面为x轴的坐标系,每次小球运动如上图所示,直接找规律,计算求解即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
scanf("%d", &t);
while(t--){
double a,b,x,y;
scanf("%lf %lf %lf %lf",&a,&b,&x,&y);
double r = atan(b / a);
double h = y - b / a * (-x);
double L = (y - h) / sin(r);
int ans = 0, sum = 0;
for(int i = 1; ; i++){
ans++;
sum += i;
if((double)sum*8.0*h*sin(r) > L){
cout << ans << '\n';
break;
}
}
}
return 0;
}