存个代码
#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; }
上面是排位赛6
下面是排位赛7
#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.18 using namespace std; int T,n,m,cnt,l,L,R,num; double k,t,ans,temp; double b[N],PI=3.14159265357939788292; bool vis[20][20][200000],flag;//zuo you xiajie shangjie struct Node{ double r,t; }a[N]; 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 S(double x1,double x2){//类扇形的面积 return 1.0/6.0*k*k*(x2*x2*x2-x1*x1*x1); } void clear(){ memset(vis,0,sizeof(vis)); flag=0; ans=0; } signed main(){ in(T); while(T--){ clear(); cin>>k; in(n); For(i,1,n) cin>>b[i]; sort(b+1,b+n+1); in(m); For(i,1,m) cin>>a[i].r>>a[i].t; For(i,1,m){ if(a[i].t>b[n]||a[i].t<b[1]){ L=n;R=1; temp=a[i].t;num=0; while(temp*k<a[i].r){ temp+=2.0*PI; num++; } if(a[i].t<b[L]&&num==0){ if(!vis[L][R][num]){ flag=1; ans+=S(0,b[R]); vis[L][R][num]=1; } continue; } if(a[i].t<b[L]) num--; if(num==0||n==1){ if(!vis[L][R][num]){ ans+=S(b[L],b[R]+2.0*PI); vis[L][R][num]=1; } } else{ if(!vis[L][R][num]){ ans+=S(b[L]+2.0*PI*(double)num,b[R]+2.0*PI*(double)num+2.0*PI)-S(b[L]+2.0*PI*(double)(num-1),b[R]+2.0*PI*(double)num); vis[L][R][num]=1; } } } else{ R=upper_bound(b+1,b+n+1,a[i].t)-b; L=R-1; temp=a[i].t;num=0; while(temp*k<a[i].r){ temp+=2.0*PI; num++; } if(num==0){ if(!vis[L][R][num]){ ans+=S(b[L],b[R]); vis[L][R][num]=1; } } else{ if(!vis[L][R][num]){ ans+=S(b[L]+2.0*PI*(double)num,b[R]+2.0*PI*(double)num)-S(b[L]+2.0*PI*(double)(num-1),b[R]+2.0*PI*(double)(num-1)); vis[L][R][num]=1; } } } } ans/=10.0; if(n==0) cout<<"Spiral "<<++cnt<<": -1"<<endl; else printf("Spiral %d: %.4f liters\n",++cnt,ans); } return 0; }