buptoj:network
2016-04-01 20:23
323 查看
F. network 第十届北京邮电大学程序设计竞赛 - 热身赛 (2)
时间限制 3000 ms 内存限制 65536KB
题目描述
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 representpeople 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) willoccur 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=0 and 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
题意挺晦涩难懂的。。。
实际上就是给出一个图,一个节点两种颜色,问有多少个节点至少连接k个不同节点。。。
和自己相连的部分c[lin[k]][k]到c[lin[k]][lin[k]],不和自己相连的2^x。
代码:
/* USER_ID: test#wangchong756 PROBLEM: 971 SUBMISSION_TIME: 2016-04-01 18:07:22 */ #pragma warning(disable:4996) #include <iostream> #include <functional> #include <algorithm> #include <cstring> #include <vector> #include <string> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <deque> #include <set> #include <map> using namespace std; typedef long long ll; #define INF 0x333f3f3f #define repp(i, n, m) for (int i = n; i <= m; i++) #define rep(i, n, m) for (int i = n; i < m; i++) #define sa(n) scanf("%d", &(n)) const ll mod = 1000000007; const int maxn = 2e5 + 5; const double PI = acos(-1.0); int n, k; ll c[35][35], f[30]; void init() { int i, j; memset(c, 0, sizeof(c)); for (i = 0; i <= 32; i++) { for (j = 0; j <= i; j++) { if (j == 0 || j == i) c[i][j] = 1; else c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } } f[0] = 1; for (i = 1; i <= 30; i++) { f[i] = (f[i - 1] << 1); } } int lin[35], val[35][35]; void solve() { int i, j; scanf("%d%d", &n, &k); memset(lin, 0, sizeof(lin)); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%d", &val[i][j]); lin[i] += val[i][j]; } } ll ans = 0; for (i = 1; i <= n; i++) { ll ans1 = 0; for (j = k; j <= lin[i]; j++) { ans1 += c[lin[i]][j]; } ans1 = ans1*(ll)(f[n - 1 - lin[i]]); ans += ans1; } double res = (double)ans / (double)f ; printf("%.3lf\n", res); } int main() { int t; init(); scanf("%d", &t); while (t--) { solve(); } return 0; }
相关文章推荐
- 回归基础系列-快速排序[JAVA]
- 【BZOJ2243】[SDOI2011]染色【树链剖分】【线段树】
- 正则大全
- hdu1166敌兵布阵<树状数组>
- 基于easyui的 增 删 改 查
- ubuntu新建用户与无密码远程登陆
- C++指针【数组、字符串作为函数的参数】
- OpenGL:太阳、地球、月球模型模拟动画
- 回归基础系列-选择排序[JAVA]
- 《Linux操作系统分析》之分析Linux内核创建一个新进程的过程
- 【BZOJ1062】[NOI2008]糖果雨【二维树状数组】
- uva10817(注意输入的解决)
- java中getResourceAsStream(String path)与getClassLoader.getResourceAsStream(String path)
- 调用一个系统命令,并读取它的输出值(使用QProcess.readAll)
- CSS--基础块级元素与内联元素
- 编译安装nginx及简单优化配置
- 电影成O2O圈地利刃 百度糯米影业进入加速快车道
- LeetCode 218. The Skyline Problem
- 用Meteor 写个即时聊天app
- sql 日期时间函数+格式转换