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. ogre--hlsl--矩阵

    重要注释——矩阵的顺序:有一件事需要牢记,HLSL允许你使用2种不同方式处理矩阵和向量相乘——mul(v,m)或者mul(m,v).二者之间唯一的区别就是矩阵被有效地变换.在OGRE中传递矩阵你应该使 ...

  2. 函数lock_rec_get_first_on_page

    lock结构体 详见 /*********************************************************************//** Gets the first ...

  3. 连接Access数据库查询语句

    --在使用之前注意将“生成”里的“配置管理器”的“配置平台”改成X86 private void button1_Click(object sender, EventArgs e)//查询 { Ole ...

  4. Qt之QHostInfo

    简述 QHostInfo 类为主机名查找提供了静态函数. QHostInfo 利用操作系统提供的查询机制来查询与特定主机名相关联的主机的 IP 地址,或者与一个IP地址相关联的主机名.这个类提供了两个 ...

  5. HDU (线段树 单点更新) 敌兵布阵

    哎,又切了一天的水题. 线段树果然必须自己写出来才能叫真正的会了,之前一直在套模板确实不好. 这个题目是单点更新 之 单点增减,= ̄ω ̄= #include <cstdio> <&l ...

  6. 基于Flume的美团日志收集系统(二)改进和优化

    在<基于Flume的美团日志收集系统(一)架构和设计>中,我们详述了基于Flume的美团日志收集系统的架构设计,以及为什么做这样的设计.在本节中,我们将会讲述在实际部署和使用过程中遇到的问 ...

  7. C#序列化XML至对象

    内容来源: http://www.cnblogs.com/fish-li/archive/2013/05/05/3061816.html#_label0 自己做的Demo下载地址:Demo

  8. 安装CouchbaseClient的过程中提示 Error 1935.An error occurred during the installation of assembly;Error:-1603 fatal error during installation

    安装过程中提示报错   点击确定后 安装程序会接着回滚,又提示报错如下       Error 1935的解决方法是下载一个微软的补丁. http://support.microsoft.com/de ...

  9. hihoCoder #1179 : 永恒游戏 (暴力枚举)

    题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...

  10. CodeIgniter 3之Session类库(2)(转)

    CI3的Session的重大改变就是默认使用了原生的Session,这符合Session类库本来的意思,似乎更加合理一些.总体来说,虽然设计理念不同,但为了保证向后兼容性,类库的使用方法与CI2.0的 ...