洛谷P1033题解

原题:

 思路:

有那么一瞬间,我以为我在做数学题

思考一下,我们会发现这样一个问题

根据题目的描述,我们可以知道,小车从某个时间开始接球,到某个时间不再接球

这期间所有的球都可以接到(因为是匀速的)

那么我们只要找出那个开始和结束的时间点,算出有效距离,求出个数即可

代码:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    double H,S1,V,L,K;
    double t0,t1,s1,s2;
    int n,ans=0;
    cin >> H >> S1 >> V >> L >> K >> n;
    t0=sqrt((H-K)/5.0);
    t1=sqrt((H)/5.0);
    s1=S1-t0*V+L+0.0001;
    s2=S1-t1*V-0.0001;
    for(int i=0;i<n;i++)
    {   
        if(i>=s2&&i<=s1)
            ans++;
    }   
    cout << ans << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/lujin49/p/13908720.html