线性期望(BUPT2015校赛.F)
2016-03-25 16:00
330 查看
将整体期望分成部分期望来做。
F.network
时间限制3000ms内存限制65536KB
Therearemanyinterestingpropertiesinasocialnetwork.Recently,weareresearchingontheSocialButterfly.Asocialbutterflyshouldsatisfythefollowingconditions:
Asimplesocialnetwork,whereCknowseveryonebutDknowsjustC.
Nowwehavealreadyhadseveralnetworksinourdatabase,butsincethedataonlycontainnodesandedges,wedon'tknowwhetheranoderepresentsamaleorafemale.Weareinterested,thatifthereareequalprobabilitiesforanodetobemaleandfemale(eachwith1/2probability).AnodeisasocialbutterflyifandonlyifthisnodeisafemaleandconnectswithatleastKmales.Whatwillbetheexpectationofnumberofsocialbutterfliesinthenetwork?
Foreachtestcase:
ThefirstlinecontainsthenumberofnodesN(1≤N≤30)andtheparameterK(0<=K<N))
ThenanN×NmatrixGfollowed,whereGij=1denotesjasafriendofi,otherwiseGij=0.Here,it'salwayssatisfiedthatGii=0andGij=Gjiforall1≤i,j≤N.
##Hint
Inthefirstsample,therearetotally4cases:{Female,Female},{Female,
Male},{Male,Female}and{Male,Male},whosenumberofsocialbutterflies
arerespectively0,1,1,0.Hence,theexpectationshouldbe
E=14×0+14×1+14×1+14×0=12
F.network
时间限制3000ms内存限制65536KB题目描述
Asocialnetworkisasocialstructuremadeupofasetofsocialactors(suchasindividualsororganizations)andasetoftherelationshipsbetweentheseactors.Insimplecases,wemayrepresentpeopleasnodesinagraph,andiftwopeoplearefriends,thenanedgeoccursbetweentwonodes.Therearemanyinterestingpropertiesinasocialnetwork.Recently,weareresearchingontheSocialButterfly.Asocialbutterflyshouldsatisfythefollowingconditions:
Asimplesocialnetwork,whereCknowseveryonebutDknowsjustC.
Nowwehavealreadyhadseveralnetworksinourdatabase,butsincethedataonlycontainnodesandedges,wedon'tknowwhetheranoderepresentsamaleorafemale.Weareinterested,thatifthereareequalprobabilitiesforanodetobemaleandfemale(eachwith1/2probability).AnodeisasocialbutterflyifandonlyifthisnodeisafemaleandconnectswithatleastKmales.Whatwillbetheexpectationofnumberofsocialbutterfliesinthenetwork?
输入格式
ThenumberoftestcasesT(T≤104)willoccurinthefirstlineofinput.Foreachtestcase:
ThefirstlinecontainsthenumberofnodesN(1≤N≤30)andtheparameterK(0<=K<N))
ThenanN×NmatrixGfollowed,whereGij=1denotesjasafriendofi,otherwiseGij=0.Here,it'salwayssatisfiedthatGii=0andGij=Gjiforall1≤i,j≤N.
输出格式
Foreachtestcase,outputtheexpectationofnumberofsocialbutterfliesin3decimals.##Hint
Inthefirstsample,therearetotally4cases:{Female,Female},{Female,
Male},{Male,Female}and{Male,Male},whosenumberofsocialbutterflies
arerespectively0,1,1,0.Hence,theexpectationshouldbe
E=14×0+14×1+14×1+14×0=12
输入样例
2 21 01 10 31 011 101 110
输出样例
0.500 1.125
// //main.cpp //160323.F // //Createdby陈加寿on16/3/25. //Copyright©2016年chenhuan001.Allrightsreserved. // #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> usingnamespacestd; #defineN31 intmat ; doubleC ; intmain(){ C[0][0]=1; for(inti=1;i<=30;i++) { C[i][0]=1; for(intj=1;j<=i;j++) { C[i][j]=C[i-1][j-1]+C[i-1][j]; } } intT; cin>>T; while(T--) { intn,k; scanf("%d%d",&n,&k); for(inti=0;i<n;i++) for(intj=0;j<n;j++) scanf("%d",&mat[i][j]); doubleans=0; for(inti=0;i<n;i++) { intcnt=0; for(intj=0;j<n;j++) { cnt+=mat[i][j]; } doubletmp=0; for(intj=k;j<=cnt;j++) tmp+=C[cnt][j]; tmp=tmp/pow(2.0,cnt); tmp*=0.5; ans+=tmp; } printf("%.3lf\n",ans); } return0; }
相关文章推荐
- DEV C++ "把着手教" 单步调试(debug)
- 关于mybatis扩展的一点想法
- org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [] [SELECT
- Android 编译环境搭建
- smarty模板引擎_2-变量的使用
- 俄罗斯方块c++
- C语言指针与数组易混淆知识点(一)
- html5学习笔记——canvas(二)
- Java中由substring方法引发的内存泄漏
- 5. Smarty3:默认的变量调解器
- 1.5.3
- 2.1.1(extra)
- 第四周项目(5)-递归求奇数积
- 实验一、命令解释程序的编写实验
- C#微信公众平台开发—高级群发接口
- C#比较dynamic和Dictionary性能
- k-Means算法Matlab实现
- ListView里的CheckBox选中后滑动时候选择错位的原因.
- 使用java.nio类库实现的Socket
- 进程间通信--管道