Describe
Jia Second is a good student of high academic achievers, but because of the IQ problem, the arithmetic is not very good, especially in solving the equation. Although he solves the equations such as 2x=2, but for the {x+y=3 X-y=1} such a group of equations is helpless. So he asked you to help. The prerequisite is a single equation set and guarantees that all problems can be handled within the range of integers.
Format input Format
The first line, a number N (1≤n≤100), represents the number of unknowns required, as well as the number of equations given.
2nd to N+1 line, each row n+1 number. The first n represents a factor of 1th to n unknowns. The number of n+1 represents the n unknowns multiplied by the respective coefficients of the sums. (Guaranteed to have a unique integer solution)
Output format
A row n number representing the 1th to n unknown value.
Template problem!
1#include <algorithm>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <iostream>6 Doublea[2005][2005];7 intN;8 intgcdintAintb) {9 if(b==0)returnA;Ten Else returnGCD (b,a%b); One } A voidGauss () { - intnow=1, TO,GGCD; - DoubleT; the for(intI=1; i<=n;i++){ - for(to=now;to<=n;to++)if(a[to][i]!=0) Break; - if(to>n)Continue; - if(To!=now) for(intj=1; j<=n+1; j + +) Std::swap (A[to][j],a[now][j]); +t=A[now][i]; - for(intj=1; j<=n+1; j + +) a[now][j]/=T; + for(intj=1; j<=n;j++) A if(j!=Now ) { att=A[j][i]; - for(intk=1; k<=n+1; k++) -a[j][k]-=t*A[now][k]; - } -now++; - } in } - intMain () { toscanf"%d",&n); + for(intI=1; i<=n;i++){ - for(intj=1; j<=n+1; j + +) thescanf"%LF",&a[i][j]); * } $ Gauss ();Panax Notoginseng for(intI=1; i<=n;i++) -printf"%d",(int) Round (a[i][n+1])); the}
Vijos 1052 Jia Dick Arithmetic (Gaussian elimination)