精度——洛谷P1033 自由落体

https://www.luogu.org/problem/show?pid=1033
这个题目卡我精度5555555555555555555555555
所以一定要把题目里给你的精度误差用起来;
我用的方法是算出球落到车顶和车底的区间;
然后通过区间算答案;
理论上是O(1);
但没他们O(n)快5555555555555555555;

#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
double h,s1,v,l,k;
int n;
int main()
{
    scanf("%lf%lf%lf%lf%lf%d",&h,&s1,&v,&l,&k,&n);
    double time_oncar=sqrt((h-k)/5);
    double carend=(s1+l)-v*time_oncar+0.0001;
    double time_under=sqrt(h/5);
    double start=s1-v*time_under-0.0001;
    int s,e,ans;
    s=start;
    if(double(s)!=start)s++;
    e=carend;
    ans=min(n-1,e)-max(0,s)+1;
    printf("%d",max(ans,0));
}

转载于:https://www.cnblogs.com/largecube233/p/6797846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值