Files
lanqiao/15lanqiao/test2.cpp
2025-03-19 14:54:46 +08:00

20 lines
690 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lanqiao 19732 小球反弹
#include<bits/stdc++.h>
using namespace std;
int main() {
int x = 343720, y = 233333, dx = 15, dy = 17;
int p = y*dx, q = x*dy;
int g = gcd(p, q);
p /= g, q /= g;
int t = 2*p*x / dx;
double ans = t * (sqrt(15*15 + 17*17));
printf("%.2lf\n", ans);
return 0;
}
/*
思路:针对前进的方向进行分解分为x方向的运动和y方向的运动假设x方向走了p个来回y反向走了q个来回
经过了时间t小球第一次回到原点则t*dx=2px,t*dy=2qy结合1式/2式得p/q=y/x*dx/dy
利用gcd对分式p,q进行约分进而得到约分后的p,q
则时间 t = 2px/dx, 总路程 = t * sqrt(15*15 + 17*17)
*/