Poj 2947 widget factory Gaussian elimination

Source: Internet
Author: User

The Gaussian element is used to describe the homogeneous equations and determine whether it is the unique solution. If it is the only output answer.

In linear algebra, there is only a unique solution if the rank of the coefficient matrix is the same as that of the augmented matrix.

If the rank of the coefficient matrix is smaller than the Augmented Matrix, there is no solution. If the rank is less than the number of variable elements, there are infinite solutions.

In addition, after making this sad question, it seems that there are some problems with Gaussian yuan.

# Include <cstdio> # include <cstring> # include <algorithm> # include <map> # include <set> # include <bitset> # include <queue> # include <stack> # include <string> # include <iostream> # include <cmath> # include <climits> using namespace STD; const int maxn = 400; int A [maxn] [maxn], n, m, ANS [maxn], fans [maxn], anscnt; char T1 [1024], t2 [1024]; int MP (char * s) {If (strcmp (S, "mon") = 0) return 1; else if (strcmp (S, "Tue") = 0) retu Rn 2; else if (strcmp (S, "wed") = 0) return 3; else if (strcmp (S, "Thu") = 0) return 4; else if (strcmp (S, "fri") = 0) return 5; else if (strcmp (S, "sat") = 0) return 6; else return 7;} int gcd (int A, int B) {return B = 0? A: gcd (B, A % B);} int lcm (int A, int B) {return a/gcd (a, B) * B ;} int getmod (int x) {return (X % 7 + 7) % 7;} //-1 indicates no solution, 0 indicates a unique solution, and 1 indicates that multiple solutions int Gauss () {int row, Col; For (ROW = 0, Col = 0; row <M & Col <n; Col ++) {int K = row; while (A [k] [col] = 0 & K <m) K ++; If (k> = m) continue; For (INT I = 0; I <= N; I ++) Swap (A [row] [I], a [k] [I]); For (INT I = 0; I <m; I ++) if (I! = Row & A [I] [col]! = 0) {int lc = lcm (ABS (A [row] [col]), ABS (A [I] [col]); int C1 = LC/A [row] [col], C2 = LC/A [I] [col]; for (Int J = 0; j <= N; j ++) {A [I] [J] = getmod (A [I] [J] * C2-A [row] [J] * C1 );}} row ++;} // unsolvable for (INT I = row; I <m; I ++) if (a [I] [N]) Return-1; // Infinitely multiple solutions if (row <n) return 1; // Unique Solution for (INT I = row-1; I> = 0; I --) {int right = A [I] [N], Left = A [I] [I]; for (Int J = I + 1; j <n; j ++) {right = getmod (right-[ I] [J] * ans [J]);} while (right % left! = 0) Right + = 7; ans [I] = right/left % 7; If (ANS [I] <3) ans [I] + = 7 ;} return 0;} void PA () {for (INT I = 0; I <m; I ++) {for (Int J = 0; j <= N; j ++) {printf ("% d", a [I] [J]);} puts ("") ;}} int main () {// freopen ("in.txt", "r", stdin); While (scanf ("% d", & N, & M )! = EOF) {If (n = 0 & M = 0) break; int K, TMP; anscnt = 0; memset (A, 0, sizeof ()); for (INT I = 0; I <m; I ++) {scanf ("% d % S % s", & K, T1, T2 ); A [I] [N] = getmod (MP (T2)-MP (T1) + 1); For (Int J = 0; j <K; j ++) {scanf ("% d", & TMP); A [I] [TMP-1] = getmod (A [I] [TMP-1] + 1 );}} int ret = Gauss (); If (ret =-1) puts ("inconsistent data. "); else if (ret = 1) puts (" multiple solutions. "); else {for (INT I = 0; I <n; I ++) printf (" % d ", ANS [I]); puts ("") ;}} return 0 ;}

  

Poj 2947 widget factory 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.