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. 如何直接在github网站上更新你fork的repo?

    玩过github的人一定会在你自己的账号上fork了一些github开源项目.这些开源项目往往更新比较活跃,你今天fork用到你自己的项目中去了,过几个星期这个fork的origin可能有一些bugf ...

  2. POJ 1743 (后缀数组 二分) Musical Theme

    看来对height数组进行分段确实是个比较常用的技巧. 题意: 一个主题是可以变调的,也就是如果这个主题所有数字加上或者减少相同的数值,可以看做是相同的主题. 一个主题在原串中至少要出现两次,而且一定 ...

  3. poj 3353 Road Construction tarjan 边双联通分支 缩点+结论

    题意:一个连通的无向图,求至少需要添加几条边,救能保证删除任意一条边,图仍然是连通的. 链接:http://poj.org/problem?id=3352 思路:边的双连通图.其实就是要求至少添加几条 ...

  4. impersonate a user

    // This sample demonstrates the use of the WindowsIdentity class to impersonate a user. // IMPORTANT ...

  5. ecshop 多语言切换

    1.打开includes/init.php找到下面两行代码并删除 require(ROOT_PATH . 'languages/' . $_CFG['lang'] . '/common.php'); ...

  6. ecshop 调用指定分类的推荐,热卖,新品

    未测试 1.includes/lib_goods.php文件.把SQL语句改一下,与category表关联即可 将 $sql = 'SELECT g.goods_id,g.goods_name, g. ...

  7. UIColor,CGColor,CIColor三者的区别和联系

    UIColor,CGColor,CIColor三者的区别和联系((转)) 最近看了看CoreGraphics的东西,看到关于CGColor的东西,于是就想着顺便看看UIColor,CIColor,弄清 ...

  8. Android 下实现图片的移动

    网上看到的demo,感觉很有趣,但是 实用性不是太强,记录一下. 源码下载地址:请戳这里---------------->

  9. db2数据库创建一张表,并为该表加上主键递增的性能和中间表的创建的sql语句

    创建角色表 CREATE TABLE NBCTXP.TBL_NBC_NONBANKROLE (    ID BIGINT NOT NULL,    ROLENAME VARCHAR(50),    C ...

  10. Thrift——初学

    是什么? Thrift是一个跨语言的服务部署框架最初由Facebook于2007年开发,2008年进入Apache开源项目.Thrift通过一个中间语言(IDL, 接口定义语言)来定义RPC的接口和数 ...