Vijos 1052 Jia Dick Arithmetic (Gaussian elimination)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.