UVALive 7455 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合并. 则题目的条件是:
化简为: 由于要求 所以 P-1 必须不可逆.
可以直接用高斯消元求P-1的秩,判断是否可逆(满秩即可逆).
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <list>
#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<int> 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;
}
转载于:https://www.cnblogs.com/Sunshine-tcf/p/5781711.html
UVALive 7455 Linear Ecosystem (高斯消元)相关推荐
- 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 ...
- 【SDOI2017】硬币游戏【KMP】【概率期望】【高斯消元】
题意:给 nnn 个长度为 mmm 的 01 串,一个 01 串初始为空,不断随机一个字符加在后面,当出现给定的 nnn 个串中的一个时停止.分别求在 nnn 个串处停止的概率. 考场思路历程: 显然 ...
- Rocksdb Ribbon Filter : 结合 XOR-filter 以及 高斯消元算法 实现的 高效filter
文章目录 前言 XOR-filter 实现原理 xor filter 的构造原理 xor filter 构造总结 XOR-filter 和 ADD-filter对比 XOR-filter 在计算上的优 ...
- poj 1681 Painter#39;s Problem(高斯消元)
http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. 注意依据自由变元求其它解及求最优值 ...
- AC自动机 + 概率dp + 高斯消元 --- HDU 5955 or 2016年沈阳icpc H [AC自动机 + 概率dp + 高斯消元]详解
题目链接 题目大意: 就是有NNN个人,每个人都会猜一个长度为LLL的只包含{1,2,3,4,5,6}\{1,2,3,4,5,6\}{1,2,3,4,5,6}的序列,现在裁判开始投掷骰子,并且把每次的 ...
- ICPC 2005 hangzhou Generator (UVA1358)KMP + 期望DP / 高斯消元
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Generator Weblink https://www.luogu.com.cn/problem/ ...
- 2020 ACM / ICPC 济南 A Matrix Equation (高斯消元、乘法原理)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 给你定义两种 010101 矩阵上的运算: Xi,j×Yi,j=(∑k=1NXi,kYk,j ...
- luogu P4035 [JSOI2008]球形空间产生器(高斯消元 / 模拟退火)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 数据范围只开到了10,而且是经典的力学结构,所以我们可以用模拟退火,可以做一下 nnn 维的正交分解h ...
- BZOJ 2707: [SDOI2012]走迷宫 [高斯消元 scc缩点]
2707: [SDOI2012]走迷宫 题意:求s走到t期望步数,\(n \le 10^4\),保证\(|SCC| \le 100\) 求scc缩点,每个scc高斯消元,scc之间直接DP 注意每次清 ...
最新文章
- python中组合框_PyQt 组合框
- 2020-11-15(IEEE浮点数计算)
- 从实例一步一步入门学习SpringCloud的Eureka、Ribbon、Feign、熔断器、Zuul的简单使用(附代码下载)
- 不通过寄存器确定数据的长度 + 案例
- .Net Core 系列:1、环境搭建
- Python学习笔记之字典(一)
- 小米新机“Davinci”跑分曝光: 单核成绩达2574分
- python读取大文件的某行_python 大文件以行为单位读取方式比对
- erp沙盘采购总监的心得_经验分享 让ERP系统操作少走冤枉路
- 正则表达式~~检索匹配的利器
- MySQL的快速修复
- MTF直播整合导航网站源码
- java判断今天是否是节假日_java 判断日期是否是节假日
- HDU3533Escape(BFS )
- torch cosine_similarity 批量两两计算cos值
- matlab画指定角度圆弧,CAD中如何根据指定的角度画圆弧
- 一个女大学生骂她男朋友的话,厉害,没一个脏字
- 什么是大数据及其背后的关键技术
- 《周志明的软件架构课》学习笔记 Day6
- 音乐播放器小程序(音乐搜索)
热门文章
- form 窗体增加边框_C#控件美化之路(13):美化Form窗口(上)
- 二十四、PHP框架Laravel学习笔记——模型的数据集合
- 一、第一个注解的 SpringMVC 程序
- LeetCode 2140. 解决智力问题(动态规划)
- 天池 在线编程 最大得分(DP)
- LeetCode 第 201 场周赛(304/5614,前5.42%)
- 剑指Offer - 面试题10- I. 斐波那契数列
- 飞思卡尔imx7 html5,i.MX6UL 飞思卡尔即将发布基于ARM Cortex-A7核心的低功耗处理器 i.MX 6UltraLite Processor...
- 怎么读取matlab程序包,Nifti程序包,用于写入,读取和处理医学影像,适用于MATLAB
- 整理总结一下:git恢复本地误删除的分支