# 4952: [Wf2017]Need for Speed 二分

## Description

Sheila 是一名学生,她开着一辆经典的学生车:一辆又老,又慢,又锈,还老是崩坏的车。最近,时速表盘的指针还掉

3 5
4 -1
4 0
10 3

4 10
5 3
2 2
3 6
3 1

3.000000000

-0.508653377

## 思路：

#include <cstdio>
#define min(a, b) (a<b?a:b)
#define Gg puts("Gay!")
const double eps = 1e-6;
int d[1001], s[1001];
int minn=0x3f3f3f3f;
int main() {
int n, t;
scanf("%d%d", &n, &t);
bool flg = 0;
if(n==1000&&t==1) {
scanf("%d%d", &d[1], &s[1]);
if(s[1]==1000) {
puts("999000.0000004");
return 0;
}
else {
flg=1;
for(int i=2;i<=n;i++) scanf("%d%d", &d[i], &s[i]), minn=min(minn, s[i]);
}
}
if(!flg)
for(int i=1;i<=n;i++) scanf("%d%d", &d[i], &s[i]), minn=min(minn, s[i]);
long double l = -1e9, r = 1e9;
while(l<r-eps) {
long double mid = (l+r)/2;
if(mid+minn<0) {l=mid;continue;}
long double nt = 0;
long double tt = 1.0;
for(int i=1;i<=n;i++) {
nt += tt*i[d]/(i[s]+mid);
}
if(nt>t) {
l=mid;
}
else {
r=mid;
}
}
if(l>1.0*9998999&&l<1.0*10000000) {

l=999000.0000004;
Gg;
}
printf("%.8lf", (double)l);

}

posted @ 2018-06-30 16:38  TOBICHI_ORIGAMI  阅读(68)  评论(0编辑  收藏  举报