线性期望(BUPT2015校赛.F)
将整体期望分成部分期望来做。
F. network
题目描述
A social network is a social structure made up of a set of social actors (such as individuals or organizations) and a set of the relationships between these actors. In simple cases, we may represent people as nodes in a graph, and if two people are friends, then an edge occurs between two nodes.
There are many interesting properties in a social network. Recently, we are researching on the SocialButterfly. A social butterfly should satisfy the following conditions:
A simple social network,where C knows everyone but D knows just C.
Now we have already had several networks in our database, but since the data only contain nodes and edges, we don't know whether a node represents a male or a female. We are interested, that if there are equal probabilities for a node to be male and female (each with 1/2 probability).A node is a social butterfly if and only if this node is a female and connects with at least K males.What will be the expectation of number of social butterflies in the network?
输入格式
The number of test cases T(T≤104) will occur in the first line of input.
For each test case:
The first line contains the number of nodes N(1≤N≤30)and the parameter K (0 <= K < N))
Then an N×Nmatrix G followed, where Gij=1 denotes j as a friend of i, otherwise Gij=0. Here, it's always satisfied that Gii=0and Gij=Gji for all 1≤i,j≤N.
输出格式
For each test case, output the expectation of number of social butterflies in 3 decimals.
##Hint
In the first sample, there are totally 4 cases: {Female, Female}, {Female,
Male},{Male, Female} and {Male, Male}, whose number of social butterflies
are respectively 0, 1, 1, 0. Hence, the expectation should be
输入样例
2
2 1
0 1
1 0
3 1
0 1 1
1 0 1
1 1 0
输出样例
0.500
1.125
//
// main.cpp
// 160323.F
//
// Created by 陈加寿 on 16/3/25.
// Copyright © 2016年 chenhuan001. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define N 31 int mat[N][N];
double C[N][N]; int main() {
C[][]=;
for(int i=;i<=;i++)
{
C[i][]=;
for(int j=;j<=i;j++)
{
C[i][j] = C[i-][j-]+C[i-][j];
}
} int T;
cin>>T;
while(T--)
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
for(int j=;j<n;j++)
scanf("%d",&mat[i][j]);
double ans=;
for(int i=;i<n;i++)
{
int cnt=;
for(int j=;j<n;j++)
{
cnt+=mat[i][j];
}
double tmp=;
for(int j=k;j<=cnt;j++)
tmp += C[cnt][j];
tmp = tmp/pow(2.0,cnt);
tmp *= 0.5;
ans += tmp;
}
printf("%.3lf\n",ans);
}
return ;
}
线性期望(BUPT2015校赛.F)的更多相关文章
- 校赛F
问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...
- 校赛F 比比谁更快(线段树)
http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...
- xdu2017校赛F
Problem F Dogs of Qwordance Senior Backend R&D Engineers 问题描述 那年夏天,锘爷和杰师傅漫步在知春公园的小道上.他们的妻子.孩子牵 着 ...
- 浙江理工2015.12校赛-F Landlocked
Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...
- 上海高校金马五校赛 F题:1 + 2 = 3?
链接:https://www.nowcoder.com/acm/contest/91/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言26214 ...
- 广州工业大学2016校赛 F 我是好人4 dfs+容斥
Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...
- 北邮校赛 F. Gabriel's Pocket Money(树状数组)
F. Gabriel's Pocket Money 2017- BUPT Collegiate Programming Contest - sync 时间限制 2000 ms 内存限制 65536 K ...
- 2018年东北农业大学春季校赛 F wyh的集合【思维】
链接:https://www.nowcoder.com/acm/contest/93/F来源:牛客网 题目描述 你们wyh学长给你n个点,让你分成2个集合,然后让你将这n个点进行两两连接在一起,连接规 ...
- 西交校赛 F. GZP and Poker
F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...
随机推荐
- Android之——获取手机安装的应用程序
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47114331 前几篇有关Android的博文中.向大家介绍了几个项目中经常使用的有 ...
- ZT:有些人,活了一辈子,其实不过是认真过了一天,其余时间都在重复这一天而已
出处:http://news.163.com/17/1011/19/D0G7UEDS0001982T.html 有些人,活了一辈子,其实不过是认真过了一天,其余时间都在重复这一天而已,也有人每天不重样 ...
- try....exception....finally
class MyException(Exception): def __init__(self,msg): self.msg=msg def __str__(self): return self.ms ...
- 用箭头函数精简Vue 模块
https://www.zcfy.cc/article/clean-up-your-vue-modules-with-es6-arrow-functions-dotdev 使用箭头函数,this指向v ...
- 【DB2】国标行业分类存储,通过SQL查询出层级关系
新建表 DROP TABLE Industry; CREATE TABLE Industry( IndustryCode VARCHAR(40),IndustryName VARCHAR(100),P ...
- IE 页面不正常显示 错误脚本不报错 脚本调试相关
在开发时,有时自己做的页面上的JS有错误,但是IE浏览器并不报错,这个时候有可能是因为脚本调试被禁止了. 在Internet选项的高级里面有 两个禁止脚本调试选项,把他们去掉就行.
- python 爬取王者荣耀高清壁纸
代码地址如下:http://www.demodashi.com/demo/13104.html 一.前言 打过王者的童鞋一般都会喜欢里边设计出来的英雄吧,特别想把王者荣耀的英雄的高清图片当成电脑桌面 ...
- HDU 4287 Intelligent IME(map运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...
- 带圈圈的数字1~50,求50以上,不要word的
①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿
- 轻松学习JavaScript十四:JavaScript的RegExp对象(正則表達式)
一RegExp对象概述 RegExp对象表示正則表達式,RegExp是正則表達式的缩写.它是对字符串运行模式匹配的强大工具. RegExp 对象用于规定在文本中检索的内容. 当您检索某个文本时.能够使 ...