- #include <iostream>
- #include <cstdio>
- #include <queue>
- #include <algorithm>
- #include <cmath>
- #include <cstring>
- #define inf 2147483647
- #define N 1000010
- #define p(a) putchar(a)
- #define For(i,a,b) for(int i=a;i<=b;++i)
- //by war
- //2019.8.16
- using namespace std;
- int T,n;
- double L,r,mid,W,L,D,V,w[N],r[N],eps=1e-10,ans,pai=3.141592653589793;
- void in(int &x){
- int y=1;char c=getchar();x=0;
- while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
- while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
- x*=y;
- }
- void o(int x){
- if(x<0){p('-');x=-x;}
- if(x>9)o(x/10);
- p(x%10+'0');
- }
- double v(double r){
- return 4.0000000/3.00000000*pai*pow(r,3);
- }
- double deal(double h,int i){
- return pai*(r[i]*r[i]*h-h*h*h/3.0);
- }
- double lj(double x,int i){
- if(x-r[i]>eps)
- return v(r[i])/2.0+deal(min(2.0*r[i],x-r[i]),i);
- return v(r[i])/2.0-deal(r[i]-x);
- }
- bool check(double x){
- double t=V;
- For(i,1,n){
- if(1.0000000-w[i]>eps){
- t+=min(v(r[i])*w[i],lj(x,i));
- }
- else
- t+=lj(x,i);
- }
- if(t/W/L-x>eps)
- return 0;
- return 1;
- }
- signed main(){
- in(T);
- while(T--){
- in(n);
- cin>>W>>L>>D>>V;
- if(V<eps){
- puts("0.0000000000");
- continue;
- }
- For(i,1,n)
- cin>>r[i]>>w[i];
- l=0;r=D;
- while(r-l>eps){
- mid=(l+r)/2.0;
- if(check(mid))
- l=mid;
- else
- r=mid;
- }
- }
- return 0;
- }
存个代码
来源: http://www.bubuko.com/infodetail-3160593.html