# [NOI2012] 骑行川藏 | 求导 二分

$E = k(v - v')^2$

$t = \frac{s}{v}$

$$\frac{dt}{dE}$$

$=\frac{dt}{dv} / \frac{dE}{dv}$

$$= -\frac{s}{v^2} / 2k(v - v')$$

$$= -\frac{s}{2kv^2(v-v')}$$

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#define enter putchar('\n')
#define space putchar(' ')
using namespace std;
typedef long long ll;
template <class T>
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op == 1) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}

const int N = 10005, INF = 0x3f3f3f3f;
int n;
double E, s[N], k[N], u[N];

double getv(double x, int i){
double l = max(u[i], double(0)), r = 100005, mid;
int cnt = 60;
while(cnt--){
mid = (l + r) / 2;
if(2 * k[i] * x * mid * mid * (mid - u[i]) > -s[i]) l = mid;
else r = mid;
}
mid = (l + r) / 2;
return (l + r) / 2;
}
double calc(double x){
double sum = 0;
for(int i = 1; i <= n; i++){
double v = getv(x, i);
sum += k[i] * (v - u[i]) * (v - u[i]);
}
return sum;
}

int main(){

scanf("%d%lf", &n, &E);
for(int i = 1; i <= n; i++)
scanf("%lf%lf%lf", &s[i], &k[i], &u[i]), k[i] *= s[i];
double l = -INF, r = 0, mid;
int cnt = 100;
while(cnt--){
mid = (l + r) / 2;
if(calc(mid) <= E) l = mid;
else r = mid;
}
mid = (l + r) / 2;
double ans = 0;
for(int i = 1; i <= n; i++)
ans += s[i] / getv(mid, i);
printf("%.10lf\n", ans);

return 0;
}

posted @ 2018-05-10 15:10  胡小兔  阅读(676)  评论(3编辑  收藏  举报