2017 World Final - need for speed

2017 World Final 解题报告

need for speed

vjudge:[need for speed]
kattis:[need for speed]
题意:已知总时间给出每段行走路程和错的里程表示数,求里程表偏差
解法:
t=i=0nd[i]s[i]+c
然后将c 二分就行,注意c的取值范围:
min(s)cINF
(v=s+c,v0
这题AC率蛮高,0.3 算是水题。。。(本人用的VS2012,有些模板没有,所以很多没用的东西23333)
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
using namespace std;
#define ll long long
#define MOD 1e9+7
#define INFLL 0x7fffff
#define INFI 0x7f7f7f7f
#define INF 0x3f3f3f3f
#define inf 0x3f
#define esp 1.0e-10
#define M(a,k) memset(a,k,sizeof a)
#ifndef ONLINE_JUDGE
template <class T> struct greater {
  bool operator() (const T& x, const T& y) const {return x>y;}
  typedef T first_argument_type;
  typedef T second_argument_type;
  typedef bool result_type;
};
#endif
const double pi=acos(-1.0);
const double es=1.0e-9;
int n,t;
int d[1005],s[1005];
int judge(double c)
{
    double cnt=0;
    for(int i=0;i<n;i++)
    {
        cnt+=(d[i]/(s[i]+c));
    }
    if(fabs(cnt-t)<=es) 
    {
        return 0;
    }
    else 
    {
        if(cnt-t>es) return 2;
        else if(cnt>0) return 1;
    }
}

int main()
{
    cin>>n>>t;
    int minn=INF;
    for(int i=0;i<n;i++)
    {
        cin>>d[i]>>s[i];
        minn=min(minn,s[i]);
    }
    double l=minn*(-1.0),r=INF*1.0,mid=0.0;
    while(fabs(r-l)>=esp)
    {
        mid=(l+r)/2.0;
        int tmp=judge(mid);
        if(tmp==0) break;
        if(tmp==2) l=mid;
        else r=mid;
    }
    printf("%.9f\n",mid);
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值