Uva10766 Organising the Organisation
题目链接戳这里
基尔霍夫矩阵裸题。构建基尔霍夫矩阵(度数矩阵-邻接矩阵),求他的任意\(n-1\)阶主子式的绝对值即为答案。
这题开始用java写,结果BigInteger太慢Tle了。
后来用c++写了个crt,不知道为什么wa了。
最后用long double强上最后输出转long long,ac了。
注意:给出的边可能有重复的。
#include<cmath>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long double ld;
typedef long long ll;
#define maxn (60)
#define eps (1e-7)
int N,M,K; ld A[maxn][maxn]; ll ans;
inline ld guass()
{
ld ret = 1; bool sign = false;
for (int i = 1,j;i < N;++i)
{
for (j = i;j < N;++j) if (fabs(A[j][i]) > eps) break;
if (j == N) { sign = true; break; }
for (int k = 1;k < N;++k) swap(A[i][k],A[j][k]);
ld inv = A[i][i]; ret *= inv;
for (j = i;j < N;++j) A[i][j] /= inv;
for (j = i+1;j < N;++j)
{
ld t = A[j][i];
for (int k = i;k < N;++k) A[j][k] -= t*A[i][k];
}
}
if (sign) ret = 0;
return fabs(ret);
}
int main()
{
freopen("10766.in","r",stdin);
freopen("10766.out","w",stdout);
while (scanf("%d %d %d",&N,&M,&K) != EOF)
{
for (int i = 1;i <= N;++i)
for (int j = 1;j <= N;++j)
{
if (i != j) A[i][j] = 1;
else A[i][i] = 0;
}
while (M--)
{
int a,b; scanf("%d %d",&a,&b);
A[a][b] = A[b][a] = 0;
}
for (int i = 1;i <= N;++i)
for (int j = 1;j <= N;++j)
if (i != j&&A[i][j] > eps) A[i][i]--;
printf("%lld\n",(ll)(guass()+0.5));
}
fclose(stdin); fclose(stdout);
return 0;
}
Uva10766 Organising the Organisation的更多相关文章
- UVA10766:Organising the Organisation(生成树计数)
Organising the Organisation 题目链接:https://vjudge.net/problem/UVA-10766 Description: I am the chief of ...
- 生成树的计数(基尔霍夫矩阵):UVAoj 10766 Organising the Organisation SPOJ HIGH - Highways
HIGH - Highways In some countries building highways takes a lot of time... Maybe that's because th ...
- 「UVA10766」Organising the Organisation(生成树计数)
BUPT 2017 Summer Training (for 16) #6C 题意 n个点,完全图减去m条边,求生成树个数. 题解 注意可能会给重边. 然后就是生成树计数了. 代码 #include ...
- Organising the Organisation(uva10766)(生成树计数)
Input Output Sample Input 5 5 2 3 1 3 4 4 5 1 4 5 3 4 1 1 1 4 3 0 2 Sample Output 3 8 3 题意: 有一张图上有\( ...
- UVa 10766 Organising the Organisation(矩阵树定理)
https://vjudge.net/problem/UVA-10766 题意: 给出n, m, k.表示n个点,其中m条边不能直接连通,求生成树个数. 思路: 这也算个裸题,把可以连接的边连接起来, ...
- UVA 10766 Organising the Organisation
https://vjudge.net/problem/UVA-10766 题意: n个员工,除总经理外每个人只能有一个直接上级 有m对人不能成为直接的上下级关系 规定k为总经理 问员工分级方案 无向图 ...
- UVa 10766 Organising the Organisation (生成树计数)
题意:给定一个公司的人数,然后还有一个boss,然后再给定一些人,他们不能成为直属上下级关系,问你有多少种安排方式(树). 析:就是一个生成树计数,由于有些人不能成为上下级关系,也就是说他们之间没有边 ...
- Uva 10766 Organising the Organisation (Matrix_tree 生成树计数)
题目描述: 一个由n个部门组成的公司现在需要分层,但是由于员工间的一些小小矛盾,使得他们并不愿意做上下级,问在满足他们要求以后有多少种分层的方案数? 解题思路: 生成树计数模板题,建立Kirchhof ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- Map的遍历方式
public class Mapper { public static void main(String[] args) { Map<String, String> map = new ...
- Magento入门开发教程
Modules->模块 Controller->控制器 Model->模型 Magento是这个星球上最强大的购物车网店平台.当然,你应该已经对此毫无疑问了.不过,你可能还不知道,M ...
- sql 判断表是否存在
if object_id(N'tablename',N'U') is not nulldrop table tablenamego if exists (select * from sysobject ...
- Java集合和PHP的对比
这里突然感觉到在java中的集合,和php的数组非常相似 .
- Android 设计随便说说之简单实践(消息流动)
在上面两篇分别说明了设计中较为简单也是很关键的实践点. 第一模块划分,它是根据每个模块所承载的业务,进行划分,是应用程序一个静态的描述. 第二合理组合,它是是将每个模块调动起来,共同实现业务,是一个准 ...
- MVC小系列(十一)【Html.BeginForm与Ajax.BeginForm】
Html.BeginForm与Ajax.BeginForm都是mvc的表单元素,前者是普通的表单提交,而后者是支持异步的表单提交,直接用mvc自带的Ajax.BeginForm就可以很容易完成一个异步 ...
- C#&JQ仿网上商城商品条件筛选功能
1.后台绑定: 一种案例: 根据第一级显示第二级,并带有每个二级的“全部”功能: #region 绑定区域 #region 绑定一级区域 ) <= ? : (PageIndex - )) + , ...
- xpath选择器
一.xpath中节点关系 父(Parent):每个元素以及属性都有一个父 子(Children):元素节点可有零个.一个或多个子 同胞(Sibling):拥有相同的父的节点 先辈(Ancestor): ...
- swift-01-利用元组判断字符串出现次数
//问题的提出:有一个字符串 array = ["1","2","4","4","2"," ...
- JavaScript之String()和.toString()
JS中 转换字符串的方法有两个 一个String(),一个.toString(). 通常情况下 这两种使用没有太大的区别.但是需要注意几点: undefined: toString() var tes ...