Linear Ecosystem

题目链接:

http://acm.hust.edu.cn/vjudge/contest/127401#problem/B

Description


http://7xjob4.com1.z0.glb.clouddn.com/99b0fe905e5bd89a24c882832c93cc09

Input


The first line of the input file contains an integer, n, which is the number of ecosystems. For each case,
the first line contains the integer k which is the number of comorgs. Followed by k lines, where the i-th
line contains, αi,1, αi,2, . . . , αi,k, the coefficients of the transition equation for ci.

Output


For each test case, output ‘1’ if the ecosystem is potentially stable, otherwise output ‘0’. Output only
5 answers per line. There should be a blank space between any two output answers.

Sample Input


6
2
4 -2
-6 5
2
2 2
0 0
3
0.3 0.2 0.5
0.4 0.4 0.2
0 0.8 0.2
3
0.3 0.2 0.5
0 0 0
0 0.8 0.2
2
4 2.0
-6 5
2
1 0
0 1

Sample Output


1 0 1 0 0
1


##题意:

对一个k元向量, 每次左乘一个k*k的矩阵得到新的向量.
问经过一定次数的左乘后,能否使得该向量不再变化. (同时要求此时向量非零)


##题解:

设初始向量为A,矩阵为P.
由于每次矩阵P都是左乘A, 那么可以把若干个P合并. 则题目的条件是:![](http://images2015.cnblogs.com/blog/764119/201608/764119-20160817202127140-716369880.png)
化简为: ![](http://images2015.cnblogs.com/blog/764119/201608/764119-20160817202208937-417784419.png) 由于要求 ![](http://images2015.cnblogs.com/blog/764119/201608/764119-20160817202227375-207951499.png) 所以 P-1 必须不可逆.
可以直接用高斯消元求P-1的秩,判断是否可逆(满秩即可逆).


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-6
#define maxn 50
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

double a[maxn][maxn],x[maxn];

int equ,var;

int Gauss()

{

int i,j,k,col,max_r;

for(k=0,col=0;k<equ&&col<var;k++,col++){

max_r = k;

for(i=k+1;i<equ;i++)

if(fabs(a[i][col])>fabs(a[max_r][col]))

max_r = i;

if(fabs(a[max_r][col])<eps) return 0; //无解,有自由变元

if(k != max_r){

for(j=col;j<var;j++)

swap(a[k][j],a[max_r][j]);

swap(x[k],x[max_r]);

}

x[k]/=a[k][col];

for(j=col+1;j<var;j++)a[k][j]/=a[k][col];

a[k][col] = 1;

for(i=0;i<equ;i++)

if(i!=k){

x[i] -= x[k]a[i][k];

for(j=col+1;j<var;j++)a[i][j]-=a[k][j]
a[i][col];

a[i][col]=0;

}

}

return 1;

}

vector ans;

int main(int argc, char const *argv[])

{

//IN;

int t; cin >> t;
while(t--)
{
memset(a, 0, sizeof(a));
cin >> equ; var = equ;
for(int i=0; i<equ; i++) {
for(int j=0; j<var; j++) {
cin >> a[i][j];
}
a[i][i] -= 1.0; /* P - 1 */
} if(Gauss()) ans.push_back(0);
else ans.push_back(1);
} for(int i=0; i<ans.size(); i++) {
printf("%d%c", ans[i], (i%5==4||i==ans.size()-1)?'\n':' ');
} return 0;

}

UVALive 7455 Linear Ecosystem (高斯消元)的更多相关文章

  1. UVaLive 7455 Linear Ecosystem (Gaussi 消元)

    题意:对一个k元向量, 每次左乘一个k*k的矩阵得到新的向量.问经过一定次数的左乘后,能否使得该向量不再变化. (同时要求此时向量非零). 析:设初始向量为A,矩阵为P.由于每次矩阵P都是左乘A, 那 ...

  2. UVALive 6449 IQ Test --高斯消元?

    题意:给你一串数字,问这串数字符合f[n] = a*f[n-1],f[n] = a*f[n-1]+b*f[n-2],f[n] = a*f[n-1]+b*f[n-2]+c*f[n-3]这几个方程中的哪个 ...

  3. First Knight UVALive - 4297(优化高斯消元解概率dp)

    题意: 一个矩形区域被分成 m*n 个单元编号为 (1, 1)至 (m, n),左上为 (1, 1),右下为(m, n).给出P(k)i,j,其中 1 ≤ i ≤ m,1 ≤ j ≤ n,1 ≤ k ...

  4. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  5. UVALive - 6185 Find the Outlier暴力填表+高斯消元+卡eps

    https://cn.vjudge.net/problem/UVALive-6185 我真的是服了orz eps 1e5,1e6过不了 开1e2 1e1都能过 题意:给你一个d阶多项式f的f(0),f ...

  6. UVALive - 3490 Generator (AC自动机+高斯消元dp)

    初始有一个空串s,从前n个大写字母中不断随机取出一个字母添加到s的结尾,出现模式串t时停止,求停止时s的长度期望. 这道题解法不唯一,比较无脑的方法是对模式串t建一个单串AC自动机,设u为自动机上的一 ...

  7. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  8. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  9. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

随机推荐

  1. Spring安全框架 Spring Security

    Spring Security 的前身是 Acegi Security ,是 Spring 项目组中用来提供安全认证服务的框架. Spring Security  为基于J2EE企业应用软件提供了全面 ...

  2. office编程必不可少 [转]

    1. 微软官方实例: 段落.表格.图表 HOW TO:利用 Visual C# .NET 使 Word 自动新建文档 2. 学习资源 (1)Word in the Office 基础知识,必读,下面的 ...

  3. Linux ARM kernel Makefile and Kconfig

    kernel build:顶层Makefile:-->1. include build/main.mk    -->2. include build/kernel.mk         k ...

  4. codevs 1228 苹果树

    dfs序+线段树 #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  5. 【英语】Bingo口语笔记(30) - 表示“拒绝”

  6. Linux初识(转)

    文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识. 本文将站在一个较高的视图来了解linux的文件系统,主要包括了linux磁盘分区和目录.挂载基本原理.文件存储结构.软链接 ...

  7. RequireJS进阶(一) 转

    为了应对日益复杂,大规模的JavaScript开发.我们化整为零,化繁为简.将复杂的逻辑划分一个个小单元,各个击破.这时一个项目可能会有几十个甚至上百个JS文件,每个文件为一个模块单元.如果上线时都是 ...

  8. String定义与方法

    //5种构造方法 public void Con(){ String str = "sfaj"; String str1 = new String("sfajdf&quo ...

  9. js 只能输入数字和小数点

    <html><head><meta http-equiv="content-Type" content="text/html;charset ...

  10. C++模板知识小结

    模板定义:模板就是实现代码重用机制的一种工具,它可以实现类型参数化,即把类型定义为参数, 从而实现了真正的代码可重用性.模版可以分为两类,一个是函数模版,另外一个是类模版. 由于类模板包含类型参数,因 ...