记录编号 274290 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOI 2012]骑行川藏 最终得分 100
用户昵称 GravatarFmuckss 是否通过 通过
代码语言 C++ 运行时间 1.541 s
提交时间 2016-06-27 19:19:01 内存使用 0.62 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int Maxn = 10005;
const double Eps = 1e-12;
const int Inf = 1e9;

int N;
double S[Maxn], K[Maxn], V[Maxn], EU;
double X[Maxn];

#define IsDig(x) (x <= '9' and x >= '0')
inline int GetNum() {
	int Ans = 0;
	char Tmp = getchar();
	
	while(!IsDig(Tmp)) Tmp = getchar();
	while( IsDig(Tmp)) {
		Ans = Ans * 10 + Tmp - '0';
		Tmp = getchar();
	}
	
	return Ans;
}

inline double GetDNum() {
	int Pre = 0, Base = 1, Suf = 0, Min = 1;
	char Tmp = getchar();
	
	while(!IsDig(Tmp)) {
		if(Tmp == '-') Min = -1;
		Tmp = getchar();
	}
	while( IsDig(Tmp)) {
		Pre = Pre * 10 + Tmp - '0';
		Tmp = getchar(); 
	} 
	
	if(Tmp == '.') Tmp = getchar();
	else return Min * Pre;
	while(IsDig(Tmp) and Base <= Inf) {
		Suf = Suf * 10 + Tmp - '0';
		Base *= 10;
		Tmp = getchar();
	} 
	
	return ((double)Pre + (double)Suf / (double)Base) * (double)Min;
}

inline double EquSol(int i, double Lam) {
	double Le = max(0.0, V[i]), Ri = Inf, Mid;
	while(Ri - Le > Eps) {
		Mid = (Le + Ri) / 2;
		double Tmp = 2.0 * Lam * K[i] * Mid * Mid * (Mid - V[i]) - 1;
		
		if(fabs(Tmp) <= Eps) break;
		if(Tmp > 0) Ri = Mid;
		else Le = Mid;
	}
	X[i] = Mid;
	return (double)K[i] * S[i] * (X[i] - V[i]) * (X[i] - V[i]);
}

inline double Judge(double Lam) {
	double Sum = 0;
	for(int i = 1; i <= N; i++) Sum += EquSol(i, Lam);
	return Sum;
}

void Read() {
	N = GetNum();
	scanf("%lf", &EU);
	for(int i = 1; i <= N; i++) {
	//	S[i] = GetDNum();
	//	K[i] = GetDNum();
	//	V[i] = GetDNum();
		scanf("%lf %lf %lf", &S[i], &K[i], &V[i]);
	}
}

inline void Solve() {
	double Le = 0, Ri = Inf, Mid;
	while(Ri - Le > Eps) {
		Mid = (Le + Ri) / 2;
		if(Judge(Mid) > EU) Le = Mid;
		else Ri = Mid; 
//		printf("%.9lf\n%.9lf\n", Mid, Judge(Mid));
	}
	double Ans = 0;
	for(int i = 1; i <= N; i++) Ans += S[i] / X[i];
	printf("%.8lf", Ans);
}

int main() {
	freopen("bicycling.in",  "r", stdin);
	freopen("bicycling.out", "w", stdout);
	Read();
	Solve();
	return 0;
}