P1033 自由落體

P1033 自由落體

題解

咱們能夠考慮小車不動,讓小球來作平拋運動,看能不能掉到車裏ios

每一個球的豎直方向上運動距離是同樣的,只須要看每一個球在水平方向上的運動距離(也就是一個位置區間[最先掉進車裏(落到車頂),最晚掉進車裏(落入車底)])可否與小車的位置區間有交集spa

注意這題容許0.0001的偏差code

代碼

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>

using namespace std;
typedef long long ll;

inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'||ch>'9') last=ch,ch=getchar();
    while(ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
    if(last=='-') ans=-ans;
    return ans;
}

double h,s,v,L,k,n;
double s1,s2;
int ans;

int main()
{
    scanf("%lf%lf%lf%lf%lf%lf",&h,&s,&v,&L,&k,&n);
    s1=v*sqrt((h-k)/5.0);s2=v*sqrt(h/5.0);
    for(int i=n-1;i>=0;i--){
        if(i+s2+0.0001<s) break;
        if(i+s1+0.0001<=s+L) ans++;
    }
    printf("%d\n",ans);
    return 0;
}
相關文章
相關標籤/搜索