Description
Input
Output
Sample Input
Example 1:
2
1 2
10 9
2
Example 2:
6
1 0 1 1 1 1
1 3 1 1 1 1
4
Example 3:
4
1 2 5 4
9 7 8 9
3
Sample Output
Example 1:
1.000000 0.000000
0.000000 1.000000
Example 2:
1.000000 0.000000
0.000000 0.750000
0.000000 1.000000
0.750000 0.250000
0.250000 0.000000
0.000000 0.000000
Example 3:
0.652778 0.000000
0.347222 0.212963
0.000000 0.930556
0.000000 0.856481
Data Constraint
Hint
Analysis: for everyone (x), we think he is the last one to enter the semi-finals, and we know the score line (cnt). {l[x]<=cnt<=r[x]}
We can know the probability of everyone entering the semi-finals.
p[i]=(r[i]-max(cnt,l[i])+1)/(r[i]-l[i]+1){i<x}
p[i]=(r[i]-max(cnt+1,l[i])+1)/(r[i]-l[i]+1){i>x}
(since we are at the bottom, we can't do the same thing at the back.)
p[i]=1 i=x
We can set f[i,j] as the probability that there are j players in the second round for the first i players
f[i,j]=f[i-1,j-1]*p[i]+f[i-1,j]*(1-p[i])
Let g[i,j] be the last i+1 to the nth person, there is a probability of j person entering the semi-finals, the same with the transfer.
So how many chances do we have for anyone y to finish at the bottom of x?
The j-th probability that he's in the K-spot is
f[i][j] * g[i][K − j], you can add this value directly to the answer. You can judge which group you are in by the value of j%4.
But since cnt is a random number in [l[x],r[x], the probability is multiplied by 1/(r[x]-l[x]+1)
code:
var le,ri:array[1..100] of longint;
f,gl,gr:array[0..30,0..30,0..3] of extended;
ans:array[1..30,0..1] of extended;
t:extended;
n,i,p:longint;
procedure calc(x,y:longint);
var i,j,k:longint;
begin
for i:=0 to n+1 do
for j:=0 to p do
for k:=0 to 3 do f[i,j,k]:=0;
f[y-1,0,0]:=1;
for i:=y-1 to n-1 do
for j:=0 to p do
for k:=0 to 3 do
if f[i,j,k]>0.1 then
begin
if ri[i+1]<x then f[i+1,j,k]:=f[i+1,j,k]+f[i,j,k]*(ri[i+1]-le[i+1]+1)
else if le[i+1]>x then f[i+1,j+1,k]:=f[i+1,j+1,k]+f[i,j,k]*(ri[i+1]-le[i+1]+1)
else
begin
if (k=2) or (k=3) then
begin
f[i+1,j,k]:=f[i+1,j,k]+f[i,j,k]*(x-le[i+1]+1);
f[i+1,j+1,k]:=f[i+1,j+1,k]+f[i,j,k]*(ri[i+1]-x);
end;
if k=1 then
begin
f[i+1,j,k]:=f[i+1,j,k]+f[i,j,k]*(x-le[i+1]);
f[i+1,j+1,k]:=f[i+1,j+1,k]+f[i,j,k]*(ri[i+1]-x+1);
f[i+1,j,2]:=f[i+1,j,2]+f[i,j,k];
end;
if k=0 then
begin
f[i+1,j,k]:=f[i+1,j,k]+f[i,j,k]*(x-le[i+1]);
f[i+1,j+1,k]:=f[i+1,j+1,k]+f[i,j,k]*(ri[i+1]-x);
f[i+1,j+1,1]:=f[i+1,j+1,1]+f[i,j,k];
f[i+1,j,3]:=f[i+1,j,3]+f[i,j,k];
end;
end;
end;
end;
procedure doit(x:longint);
var i,j,k,l:longint;
s,s1:extended;
begin
for i:=0 to n+1 do
for j:=0 to p+1 do
for k:=0 to 3 do begin gl[i,j,k]:=0;gl[i,j,k]:=0; end;
gl[0,0,0]:=1;gr[n+1,0,0]:=1;
calc(x,1);
for j:=0 to p do
for k:=0 to 3 do gr[1,j,k]:=f[n,j,k];
for i:=1 to n do
for j:=0 to p do
for k:=0 to 3 do gl[i,j,k]:=f[i,j,k];
for i:=2 to n do
begin
calc(x,i);
for j:=0 to p do
for k:=0 to 3 do gr[i,j,k]:=f[n,j,k];
end;
for i:=1 to n do
for j:=1 to p do
if ri[i]>=x then
begin
l:=ri[i]-x;if le[i]>x then l:=ri[i]-le[i]+1;
s:=gl[i-1,j-1,0]+gl[i-1,j-1,1];s:=s*l;
s:=s*(gr[i+1,p-j,0]+gr[i+1,p-j,1]+gr[i+1,p-j,2]+gr[i+1,p-j,3]);
s:=s-(gl[i-1,j-1,0]*l)*(gr[i+1,p-j,0]+gr[i+1,p-j,3]);
s1:=s;
s:=gl[i-1,j-1,2]*l;s:=s*(gr[i+1,p-j,0]+gr[i+1,p-j,3]);
s1:=s1+s;
l:=1;if le[i]>x then l:=0;
s:=gl[i-1,j-1,0]+gl[i-1,j-1,1];s:=s*l;
s:=s*(gr[i+1,p-j,0]+gr[i+1,p-j,1]+gr[i+1,p-j,2]+gr[i+1,p-j,3]);
s1:=s1+s;
l:=j mod 4;
if (l=2) or (l=3) then ans[i,1]:=ans[i,1]+s1 else ans[i,0]:=ans[i,0]+s1;
end;
end;
begin
readln(n);
for i:=1 to n do read(le[i]);
for i:=1 to n do read(ri[i]);
for i:=1 to n do begin ans[i,0]:=0;ans[i,1]:=0; end;
readln(p);
for i:=0 to 1000 do
begin
p:=p;
doit(i);
end;
t:=1;
for i:=1 to n do t:=t*(ri[i]-le[i]+1);
for i:=1 to n do
begin
ans[i,0]:=ans[i,0]/t;
ans[i,1]:=ans[i,1]/t;
end;
for i:=1 to n do writeln(ans[i,0]:0:6,' ',ans[i,1]:0:6);
end.