2017 World Final 解题报告
need for speed
题意:已知总时间给出每段行走路程和错的里程表示数,求里程表偏差
解法:
t = ∑ i = 0 n d [ i ] s [ i ] + c
然后将c 二分就行,注意c的取值范围:
− m i n ( s ) ≤ c ≤ I N F
( 原 因 : v = s + c , v ≥ 0 )
这题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 ;
}