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 ...
随机推荐
- 手机端轻应用模拟原生的下拉刷新效果(JavaScript)
方案一:使用iscoll等有下拉功能的框架. 分析:因为项目的结构已经基本完成,再使用框架,会与原来的结构互相影响: 方案二:用JavaScript.Jquery写. 分析:可能没有直接使用框架的效果 ...
- File类最基础知识
package File; /** * 创建一个文件: * 判断是否存在,若存在,则创建,若不存在,则删除,最后输出文件是否存在. */ import java.io.File; import jav ...
- Windows 7中,用Visual Studio开发WPF应用程序,实现从Windows Explorer中拖拽文件到应用程序,始终显示“无法拖放”符号问题解决方案
Are you running your application or Visual Studio that hosts the app under administrative privilege? ...
- Cordova5 -- iOS实战(一)
由于最近公司的项目要求用Cordova来进行开发,便开始了对Cordova的学习.由于本人之前也是做iOS开发,因此相关内容主要从iOS平台的角度来写.刚开始学习Cordova这个平台,希望以此总 ...
- 根据id设置、获取元素的文本和value
/** * 根据id获取元素文本 * @param {String} id|元素id * return {Integer || String} text */function getText(id){ ...
- UVA 11462 Age Sort(计数排序法 优化输入输出)
Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...
- UVA 1401 Remember the Word(用Trie加速动态规划)
Remember the Word Neal is very curious about combinatorial problems, and now here comes a problem ab ...
- 暑假集训(1)第八弹 -----简单迷宫(Poj3984)
Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...
- iframe框根据内容自适应高度
1.页面 <iframe name="iframe_userCenter" id="iframe" frameborder=2 width=100% he ...
- C++写一个排列组合小程序
今天突然想到一个问题,有时候,针对同一个事件有多种反映,特别是游戏AI当中,这种情况下需要采取最适合的方案,哪种方案最适合,可以将每种方案的结果或影响都计算一遍,从而选择最合适的.最基本就是一个排列组 ...