http://www.lydsy.com/JudgeOnline/problem.php?id=2876
表示完全不会。。。。。。
还是跪拜大神吧
http://www.cnblogs.com/GerynOhenz/p/4698451.html
#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #include<bitset> #include<vector> #include<functional> #include<deque> #include<cctype> #include<climits> #include<complex> //#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL; typedef double DB; typedef pair<int,int> PII; typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a)) #define mmcy(a,b) memcpy(a,b,sizeof(a)) #define fill(a,l,r,v) fill(a+l,a+r+1,v) #define re(i,a,b) for(i=(a);i<=(b);i++) #define red(i,a,b) for(i=(a);i>=(b);i--) #define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++) #define fi first #define se second #define m_p(a,b) make_pair(a,b) #define SF scanf #define PF printf #define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;} template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;} template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-10; inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;} const DB Pi=acos(-1.0); inline int gint() { int res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } inline LL gll() { LL res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } const int maxN=10000; int N; DB E,s[maxN+10],k[maxN+10],tv[maxN+10],v[maxN+10]; DB lambda,ans; inline void calc_v() { int i; re(i,1,N) { DB L=0.0,R=1e4; while(L<R) { DB mid=(L+R)/2.0,temp=2.0*k[i]*sqr(mid)*(mid-tv[i]); if(sgn(temp-lambda)==0) { v[i]=mid; break; } if(temp<lambda) L=mid; else R=mid; } } } inline int check() { int i; DB res=0.0; re(i,1,N)res+=k[i]*sqr(v[i]-tv[i])*s[i]; return res<=E; } inline void calc_ans(){int i;ans=0.0;re(i,1,N)ans+=s[i]/v[i];} inline void solve() { DB L=0.0,R=1e5; while(L+EPS<R) { lambda=(L+R)/2.0; calc_v(); if(check()) L=lambda; else R=lambda; } calc_v(); calc_ans(); } int main() { /*freopen("bicycling.in","r",stdin); freopen("bicycling.out","w",stdout);*/ int i; SF("%d %lf\n",&N,&E); re(i,1,N)SF("%lf %lf %lf\n",&s[i],&k[i],&tv[i]); solve(); PF("%0.8lf\n",ans); return 0; }
时间: 2024-10-26 01:02:04