UVA 10766 Organising the Organisation(生成树计数)
来源:互联网 发布:免费淘宝手机模板 编辑:程序博客网 时间:2024/06/06 03:50
题目链接:
UVA 10766 Organising the Organisation
题意:
给出
数据范围:
分析:
我觉得
把关系图看成一颗生成树,其实把所有可以存在领属关系的点看成可以连边,那么就是求生成树的个数了。
需要知道每个点的度数和点与点能够连边。
我是先默认每个点的度数为
这道题还要用
输入输出可以使用
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#include <iomanip>#define IOS ios_base::sync_with_stdio(0); cin.tie(0);using namespace std;typedef long long ll;const int MAX_N = 110;const double eps = 1e-8;int degree[MAX_N];long double C[MAX_N][MAX_N];int sgn(long double x){ if(fabs(x) < eps) return 0; else if(x > 0) return 1; else return -1;}long double det(long double mat[][MAX_N], int n){ long double res = 1.0; int cnt = 0; for(int i = 0; i < n; ++i) { if(sgn(mat[i][i]) == 0) { for(int j = i + 1; j < n; ++j) { if(sgn(mat[j][i] != 0)) { for(int k = i; k < n; ++k) { swap(mat[i][k], mat[j][k]); } cnt++; break; } } } if(sgn(mat[i][i]) == 0) return 0; res *= mat[i][i]; for(int j = i + 1; j < n; ++j) { mat[j][i] /= mat[i][i]; } for(int j = i + 1; j < n; ++j) { for(int k = i + 1; k < n; ++k) { mat[j][k] -= mat[j][i] * mat[i][k]; } } } if(cnt & 1) res = -res; return res;}int main(){ int n, m, k; while(cin >> n >> m >> k) { memset(degree, 0, sizeof(degree)); memset(C, 0, sizeof(C)); for(int i = 0; i < n; ++i) { degree[i] = n - 1; //默认每个点的入度为n - 1 for (int j = 0; j < n; ++j) { //先默认任意两点可以建边 C[i][j] = -1; } } for(int i = 0; i < m; ++i) { int a, b; cin >> a >> b; a--, b--; if(sgn(C[a][b]) == 0) continue; //会有重边啊!!! C[a][b] = C[b][a] = 0; //不能建边 degree[a]--, degree[b]--; } for(int i = 0; i < n; ++i) { C[i][i] = degree[i]; } cout << fixed << setprecision(0) << det(C, n - 1) << endl; } return 0;}
0 0
- UVA 10766 Organising the Organisation 生成树计数
- UVA 10766 Organising the Organisation(生成树计数 不取模)
- UVA 10766(Organising the Organisation-补图生成树计数)
- UVA 10766 Organising the Organisation(生成树计数)
- UVA 10766 Organising the Organisation生成树计数
- UVA10766(Organising the Organisation)生成树计数-Matrix-Tree定理
- uva10766 Organising the Organisation(生成树计数模板)
- Organising the Organisation UVA
- 10766 Organising the Organisation
- UVA10766-Organising the Organisation(生成树计数+Matrix-tree定理)
- uva 10766 生成树计数
- TOJ 3886 Simplifying the Farm / 最小生成树+计数
- uva 11481 - Arrange the Numbers(计数问题)
- Where is the Marble? uva 计数排序
- 生成树计数
- NOI2008 生成树计数
- 《生成树计数》预处理
- 生成树计数
- Django: 新建你的第一个blog应用
- Centos下安装mysql5.6
- 2016夏季练习——数论
- 292. Nim Game
- [ 错误 ] - app没有显示在admin中
- UVA 10766 Organising the Organisation(生成树计数)
- 置顶 一位近60岁的美国程序员令我狼狈不堪的回复
- 数据类型转换
- 有关文件的操作 fopen/fwriite/fseek/ftell/fread/fclose等函数的使用方法
- 七牛直播鉴权方式
- Java学习一(JDK环境搭建)
- 写给自己的北漂生涯
- HTML5中表单元素常用的属性设置
- 安卓学习笔记--- dp与Px之间的换算