QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211502#5740. Testing Subjects Usually DieAFewSunsWA 1ms5632kbC++142.0kb2023-10-12 17:26:182023-10-12 17:26:19

Judging History

你现在查看的是最新测评结果

  • [2023-10-12 17:26:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5632kb
  • [2023-10-12 17:26:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll n;
db p[100010],sum[100010],q[100010],c;
il bl solve(db S){
	db D=sqrt(c*c*S+(1-c)*(c*S+1));
	fr(i,1,n){
		db k=(n*c+1-c)/D/sum[i];
		if((D*p[i]*k-c)>=0){
			fr(j,1,i-1) q[j]=0;
			fr(j,i,n) q[j]=(D*p[j]*k-c)/(1-c);
			break;
		} 
	}
	db now=0;
	fr(i,1,n) now+=p[i]*p[i]*(1+(1-q[i])*c*S)/(1-(1-q[i])*(1-c));
	return now<=S;
}
int main(){
	n=read();
	c=0.01*read();
	fr(i,1,n) p[i]=read();
	sort(p+1,p+n+1);
	ll all=0;
	fr(i,1,n) all+=p[i];
	fr(i,1,n) p[i]/=all;
	if(c==1){
		pf("%.7lf",1.0/p[n]);
		return 0;
	}
	fr(i,1,n) p[i]=sqrt(p[i]);
	pfr(i,n,1) sum[i]=sum[i+1]+p[i];
	db l=0,r=1e9;
	while(fabs(r-l)>1e-7){
		db mid=(l+r)*0.5;
		if(solve(mid)) r=mid;
		else l=mid;
	}
	pf("%.7lf",l);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

4 100
25 25 25 25

output:

4.0000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5632kb

input:

2 0
1 4

output:

1.8000000

result:

ok found '1.8000000', expected '1.8000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

5 0
245 802 95 452 756

output:

4.4685310

result:

ok found '4.4685310', expected '4.4685310', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

5 10
85 144 62 67 925

output:

3.0823373

result:

ok found '3.0823373', expected '3.0823373', error '0.0000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

5 20
573 598 705 893 279

output:

4.6655640

result:

ok found '4.6655640', expected '4.6655641', error '0.0000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

5 25
533 195 166 109 527

output:

3.9338079

result:

ok found '3.9338079', expected '3.9338079', error '0.0000000'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3640kb

input:

5 50
498 942 71 637 663

output:

1.9984427

result:

wrong answer 1st numbers differ - expected: '3.8718857', found: '1.9984427', error = '0.4838580'