Poj2947--widget Factory (Gaussian elimination Element)

Source: Internet
Author: User
Tags strcmp

Topic Link: Click to open the link

Main topic: There are n kinds of parts, it is known that the processing time of each part is at least 3 days up to 9 days, now only know that there are M engineering time and the number of parts processed, asked to find out the processing time of each part.

The M equations of 7 are listed, and the solution is determined by using the Gaussian elimination element.

#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #pragma comment (linker, "/stack:102400000,102400000"); int map[310][310], a[310]; char str[8][10] = {"S", "MON", "TUE", "WED", "THU", "FRI", "SAT",    "SUN"}; char s1[10], s2[10]; int n, M, ans[310]; int solve () {int I, j, k = 1, l, temp, num = 0, sum;         for (i = 1; I <= m && k <= N; i++) {for (j = i; J <= M; j + +) if (map[j][k]) break;            if (J > m) {k++; i--;        Continue;            } if (J! = i) {for (L = k; l <= N; l++) swap (map[i][l],map[j][l]);        Swap (a[i],a[j]); } for (j = i+1; J <= M; j + +) {if (!            MAP[J][K]) continue;            temp = Map[j][k];                for (L = k; l <= N; l++) {map[j][l] = map[i][l]*temp-map[j][l]*map[i][k];            Map[j][l] = (map[j][l]%7 + 7)% 7; } A[j] = a[I]*temp-a[j]*map[i][k];        A[J] = (a[j]%7+7)%7;        } num++;    k++;    } sum = 0;    for (i = num+1; I <= m; i++) if (A[i]) return 0;    if (num! = n) return 1;            for (i = n, i >= 1; i--) {for (j = i+1; J <= N; j + +) {A[i] = a[i]-ans[j]*map[i][j];        A[i] = (a[i]%7+7)%7;        } Ans[i] = 0;        for (j = 3; J <= 9; j + +) {if (map[i][i]*j%7 = = A[i]) ans[i] = j;    }//if (!ans[i]) return 0; } return 2;}    int main () {int num, I, J, K1, K2, X;        while (scanf ("%d%d", &n, &m) && n+m) {memset (map,0,sizeof (MAP));            for (i = 1; I <= m; i++) {scanf ("%d%s%s", &num, S1, S2);                for (j = 1; J <= 7; j + +) {if (!strcmp (str[j],s1)) K1 = j;            if (!strcmp (STR[J],S2)) K2 = j;            } A[i] = (k2-k1+1+7)%7;  while (num--) {              scanf ("%d", &x);            MAP[I][X] = (map[i][x]+1)%7;        }} K1 = Solve ();        if (K1 = = 0) printf ("Inconsistent data.\n");        else if (k1 = = 1) printf ("Multiple solutions.\n");            else {for (i = 1; i < n; i++) printf ("%d", ans[i]);        printf ("%d\n", Ans[n]); }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Poj2947--widget Factory (Gaussian elimination Element)

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.