记录编号 300812 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOI 2012]骑行川藏 最终得分 100
用户昵称 GravatarFoolMike 是否通过 通过
代码语言 C++ 运行时间 1.078 s
提交时间 2016-08-29 01:02:03 内存使用 0.60 MiB
显示代码纯文本
#include<cstdio>
#include<cmath>
using namespace std;
const int N=10010;
const double eps=1e-10;
int n;double Eu,s[N],k[N],v[N],ans[N],c,Max[N];
inline double sqr(double x){return x*x;}
inline double val(int i,double x){return k[i]*x*x*(x-v[i]);}
double solve(int i,double l,double r,double c){//求解方程ki*ansi^2*(ansi-vi)=c 
	if (abs(l-r)<=eps) return l;
	double mid=(l+r)/2;
	return val(i,mid)>c?solve(i,l,mid,c):solve(i,mid,r,c);
}
void A(){
	
}
double erfen(double l,double r){
	if (abs(l-r)<=eps) return l;
	double mid=(l+r)/2,level=val(1,mid),sum=0;
	for (int i=1;i<=n;i++){
		if (i==216) A();
		ans[i]=solve(i,v[i],Max[i],level);
	}
	for (int i=1;i<=n;i++)
		sum+=k[i]*s[i]*sqr(ans[i]-v[i]);
	return sum>Eu?erfen(l,mid):erfen(mid,r);
}
int main()
{
	freopen("bicycling.in","r",stdin);
	freopen("bicycling.out","w",stdout); 
	scanf("%d%lf",&n,&Eu);
	for (int i=1;i<=n;i++){
		scanf("%lf%lf%lf",&s[i],&k[i],&v[i]);
		if (abs(s[i])<=eps) s[i]=eps;
		if (abs(k[i])<=eps) k[i]=eps;
		if (abs(v[i])<=eps) v[i]=eps;
		Max[i]=sqrt(Eu/k[i]/s[i])+v[i];
	}
	c=erfen(v[1],Max[1]);
	double Ans=0,level=val(1,c);
	for (int i=1;i<=n;i++){
		ans[i]=solve(i,v[i],Max[i],level);
		Ans+=s[i]/ans[i];
	}
	printf("%.8lf\n",Ans);
	return 0;
}