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. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  2. HDU 2897 (博弈 找规律) 邂逅明下

    根据博弈论的两条规则: 一个状态是必胜状态当且仅当有一个后继是必败状态 一个状态是必败状态当且仅当所有后继都是必胜状态 然后很容易发现从1开始,前p个状态是必败状态,后面q个状态是必胜状态,然后循环往 ...

  3. HDU 3068 (Manacher) 最长回文

    求一个字符串的最长子串,Manacher算法是一种O(n)的算法,很给力! s2[0] = '$',是避免在循环中对数组越界的检查. 老大的代码: http://www.cnblogs.com/Big ...

  4. ui/ue设计师应该了解的原型设计软件

    前段实践整理过一些原型设计用的软件,这里分享一下,喜欢对更多的PM战线的童鞋有所裨益.(因为交互原型工具Axure ui设计师都很常用了,文中就不专门介绍了) 首先分下类: •1.交互原型(产品能做什 ...

  5. [转] POJ计算几何

    转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...

  6. php的session_start

    如果session使用cookie记录,那么在session_start时会设置一个cookie,参数取决于php.ini的设置,当然也可以通过session_set_param在程序里设置.不同站点 ...

  7. KVM虚拟化技术简介

    kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中.它使用Linux自身的调度器进行管理,所 ...

  8. Android下监听Home键

    网上看到demo,亲测了以下机器和设备,均测试通过: 测试通过的手机: 1.华为荣耀3(Android 4.2.2) 2.小米2s(Android 4.1.1) 3.联想的手机 (Android2.3 ...

  9. RAC实例 表空间 维护

    先配置一下监听,这样我们就可以从客户端进行连接了. 我这里写了三种连接. 第一种是正常方式,一般都采用这种方式,后面的rac1和rac2 是方便测试.因为如果用第一种方式的话,客户端连哪个实例是随机的 ...

  10. Arduino命令行编译 树莓派连接Arduino 电脑上编译Arduino代码后 通过树莓派烧写到Arduino上

    //本教程针对UNO 1.在file->preferences中找到preferences.txt文件 2:用记事本打开preferences.txt,选择hex文件存放的路径,在最后行加入 b ...