将整体期望分成部分期望来做。

F. network

时间限制 3000 ms 内存限制 65536 KB

题目描述

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

E=14×0+14×1+14×1+14×0=12

输入样例

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)的更多相关文章

  1. 校赛F

    问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...

  2. 校赛F 比比谁更快(线段树)

    http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...

  3. xdu2017校赛F

    Problem F Dogs of Qwordance Senior Backend R&D Engineers 问题描述 那年夏天,锘爷和杰师傅漫步在知春公园的小道上.他们的妻子.孩子牵 着 ...

  4. 浙江理工2015.12校赛-F Landlocked

    Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...

  5. 上海高校金马五校赛 F题:1 + 2 = 3?

    链接:https://www.nowcoder.com/acm/contest/91/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言26214 ...

  6. 广州工业大学2016校赛 F 我是好人4 dfs+容斥

    Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...

  7. 北邮校赛 F. Gabriel's Pocket Money(树状数组)

    F. Gabriel's Pocket Money 2017- BUPT Collegiate Programming Contest - sync 时间限制 2000 ms 内存限制 65536 K ...

  8. 2018年东北农业大学春季校赛 F wyh的集合【思维】

    链接:https://www.nowcoder.com/acm/contest/93/F来源:牛客网 题目描述 你们wyh学长给你n个点,让你分成2个集合,然后让你将这n个点进行两两连接在一起,连接规 ...

  9. 西交校赛 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 ...

随机推荐

  1. 基于Spring开发的DUBBO服务接口测试

    基于Spring开发的DUBBO服务接口测试 知识共享主要内容: 1. Dubbo相关概念和架构,以及dubbo服务程序开发步骤. 2. 基于Spring开发框架的dubbo服务接口测试相关配置. 3 ...

  2. 使用zbar 解码二维码 条形码

    #!/usr/bin/env python # coding: u8 import os import zbar import Image import urllib import uuid def ...

  3. cocos2d-x OpenGL ES 坐标系总结

    很多教程都说cocos2d-x OpenGL ES世界坐标系原点在左下角,但至于为什么在左下角却从来没有人提过,这导致大部分人觉得这是OpenGL ES的规定,事实上这是错的.OpenGL ES的坐标 ...

  4. Activity设置切换动画时黑屏问题的解决

    //当这么设置的时候.打开Acticity的时候会黑屏一下 overridePendingTransition(R.anim.activity_open,0); //改成例如以下代码 完美解决这个问题 ...

  5. 理解shell中的atime,mtime,ctime

    所有文件都有3个时间信息,保存在文件系统中 atime (Access time)是文件最后一此读的时间 或者执行文件的时间 mtime (Modified time)是文件最后一次写的时间(是在写入 ...

  6. ps -ef/ps -aux 查看正在活动的进程

    ps -ef 查看正在活动的进程 ps -ef |grep abc 查看含有"abc"的活动进程 ps -ef |grep -v abc 查看不含abc的活动进程 1)ps a 显 ...

  7. php中在局部作用域内访问全局变量

    php中,由于作用域的限制,导致变量的访问限制: 1.局部作用域内不能访问全局变量 2.全局作用域内不能访问局部变量 对于第一种情况,如下代码将不能正常运行: <?php //局部作用域(函数内 ...

  8. jetty.xml解析

    我们知道jetty有一种启动方式是在jetty的根目录中运行命令行:java -jar start.jar,这个命令会调用apache的XmlConfiguration工具类作为启动类,这个类会默认读 ...

  9. 通过windows自带的系统监视器来查看IIS并发连接数(perfmon.msc)

    如果要查看IIS连接数,最简单方便的方法是通过“网站统计”来查看,“网站统计”的当前在线人数可以认为是当前IIS连接数.然而,“网站统计”的当前在线人数统计时间较长,一般为10分钟或15分钟,再加上统 ...

  10. Centos 删除用户

    # 查看用户 tail /etc/passwd # 删除用户 userdel -rf ftpuser1