【BZOJ4481&JSOI2015】非诚勿扰(数学期望)
听说JSOI有版权问题就不放图了
如果前面的文章里的图需要删掉请通知我
题意:有一些女的要挑一些男的,挑中的几率均为p。一个男的可以无限次被挑中。若女a选中男b,女c选中男d,a<c,b>d则对答案有1的贡献。问期望总贡献。
思路:我们设女x选中男y的几率是p(X,Y),可以预处理出。
设y为女x喜欢的第a人。
则P(x,y)=(1-p)^a-1*p+(1-p)^m+a-1*p+... 无限等差数列求和
=a1/(1-q) a1=(1-p)^(a-1)*p,q=(1-p)^m
先将关系双关键字递增排序 那么用树状数组统计前缀概率和
没了
1 var x,y:array[1..1000000]of longint; 2 t:array[1..1000000]of extended; 3 mi:array[0..1000000]of extended; 4 n,m,i,now,j,k:longint; 5 tmp,ans,p:extended; 6 7 function lowbit(x:longint):longint; 8 begin 9 exit(x and (-x)); 10 end; 11 12 procedure add(x:longint;y:extended); 13 begin 14 while x>0 do 15 begin 16 t[x]:=t[x]+y; 17 x:=x-lowbit(x); 18 end; 19 end; 20 21 function sum(x:longint):extended; 22 begin 23 sum:=0; 24 while x<=n do 25 begin 26 sum:=sum+t[x]; 27 x:=x+lowbit(x); 28 end; 29 end; 30 31 procedure swap(var x,y:longint); 32 var t:longint; 33 begin 34 t:=x; x:=y; y:=t; 35 end; 36 37 procedure qsort(l,r:longint); 38 var mid1,mid2,i,j:longint; 39 begin 40 i:=l; j:=r; mid1:=x[(l+r)>>1]; mid2:=y[(l+r)>>1]; 41 repeat 42 while (mid1>x[i])or(mid1=x[i])and(mid2>y[i]) do inc(i); 43 while (mid1<x[j])or(mid1=x[j])and(mid2<y[j]) do dec(j); 44 if i<=j then 45 begin 46 swap(x[i],x[j]); 47 swap(y[i],y[j]); 48 inc(i); dec(j); 49 end; 50 until i>j; 51 if l<j then qsort(l,j); 52 if i<r then qsort(i,r); 53 end; 54 55 begin 56 assign(input,'cross.in'); reset(input); 57 assign(output,'cross.out'); rewrite(output); 58 readln(n,m); 59 readln(p); 60 for i:=1 to n do read(x[i],y[i]); 61 qsort(1,m); 62 mi[0]:=1; 63 for i:=1 to n do mi[i]:=mi[i-1]*(1-p); 64 now:=1; 65 for i:=1 to n do 66 begin 67 j:=now; 68 while x[j]=i do inc(j); 69 for k:=now to j-1 do 70 begin 71 tmp:=mi[k-now]*p/(1-mi[j-now]); 72 //writeln(tmp); 73 ans:=ans+tmp*sum(y[k]+1); 74 add(y[k],tmp); 75 end; 76 now:=j; 77 end; 78 writeln(ans:0:2); 79 80 close(input); 81 close(output); 82 end.
null