[Poj] 2947 widget Factory (Gaussian deyuan)

Source: Internet
Author: User

Http://poj.org/problem? Id = 2947

All kinds of fun .. Okay, 1a ..

I won't talk about it anymore.

To mod equations, that is

(X [1, 1] * A [1]) + (X [1, 2] * A [2]) +... + (X [1, N] * A [n]) = x [1, n + 1] (mod m)

(X [2, 1] * A [1]) + (X [2, 2] * A [2]) +... + (X [2, N] * A [n]) = x [2, n + 1] (mod m)

...

(X [N, 1] * A [1]) + (X [N, 2] * A [2]) +... + (X [N, N] * A [n]) = x [N, N + 1] (mod m)

If there is no mod, It is the bare Gaussian deyuan...

Let's consider how to cancel the RMB.

Obviously, if there are equations 1 and 2, and they both have elements y with the same coefficient but not 0, we only need to adjust their coefficients to the same value, that is, to convert them to a public multiple, in the MOD sense, a * c = B (mod m), A * c = B * C (mod m ), so we can multiply the Left and Right formulas of the two equations by this public factor.

The back generation is somewhat troublesome. After the corresponding values of other elements in the current equation are subtracted, we assume that the coefficient of the current element is a [I] [I]. the value is a [I] [n + 1], because X * A [I] [I] = A [I] [n + 1] (mod m ), we can extend Euclidean or add m all the time to know that the equation is true (because there must be a solution at this time, we must find an X to make the equation true)

The resulting X is the answer.

Pay attention to whether N and m are the number of equations or the number of unknown numbers ..

 

# Include <cstdio> # include <cstring> # include <cmath> # include <string> # include <iostream> # include <algorithm> # include <queue> using namespace STD; # define rep (I, n) for (INT I = 0; I <(n); ++ I) # define for1 (I, A, n) for (INT I = (a); I <= (n); ++ I) # define for2 (I, A, n) for (INT I = (); I <(n); ++ I) # define for3 (I, A, n) for (INT I = (a); I> = (n); -- I) # define for4 (I, A, n) for (INT I = (a); I> (n); -- I) # define CC (I, A) memset (I, a, sizeof (I ))# Define read (A) A = getint () # define print (a) printf ("% d", a) # define dbg (x) cout <(# X) <"=" <(x) <Endl # define printarr2 (a, B, c) for1 (_, 1, B) {for1 (__, 1, C) cout <A [_] [_]; cout <Endl ;}# define printarr1 (a, B) for1 (_, 1, B) cout <A [_] <'\ T'; cout <endlinline const int getint () {int r = 0, k = 1; char c = getchar (); for (; C <'0' | C> '9'; C = getchar () if (C = '-') k =-1; (; c> = '0' & C <= '9 '; C = getchar () r = r * 10 + C-'0'; return K * r;} inline const int max (const Int &, const Int & B) {return A> B? A: B;} inline const int min (const Int & A, const Int & B) {return a <B? A: B;} const int n = 305; typedef int CTX [N] [N]; string dt [7] = {"mon", "Tue", "wed ", "Thu", "fri", "sat", "Sun"}; int Gauss (ctx a, int N, int M, int MD) {int x = 1, y = 1, Pos; while (x <= N & Y <= m) {pos = x; while (! A [POS] [Y] & Pos <= N) ++ Pos; if (a [POS] [Y]) {for1 (I, 1, m + 1) swap (A [POS] [I], a [x] [I]); for1 (I, x + 1, n) if (a [I] [Y]) {int L = A [x] [Y], r = A [I] [Y]; for1 (J, Y, m + 1) A [I] [J] = (a [I] [J] * l-A [x] [J] * r) % MD + MD) % md ;} ++ x ;}++ y ;}for1 (I, X, n) if (a [I] [M + 1]) Return-1; if (x <= m) return M-x + 1; for3 (I, m, 1) {for1 (J, I + 1, m) if (A [I] [J]) A [I] [M + 1] = (A [I] [M + 1]-(A [J] [M + 1] * A [I] [J] )) % MD + MD) % md; while (A [I] [M + 1] % A [I] [I]! = 0) A [I] [M + 1] + = md; // you can use the extension here .. A [I] [M + 1] = (a [I] [M + 1]/A [I] [I]) % md;} return 0 ;} inline int get (string s) {return find (DT, DT + 7, S)-dT + 1;} int main () {int n = getint (), M = getint (), T; char s [2] [5]; ctx a; while (N | M) {CC (A, 0); for1 (I, 1, m) {read (t); scanf ("% S % s", s [0], s [1]); A [I] [n + 1] = (get (s [1])-Get (s [0]) + 1 + 7) % 7; for1 (J, 1, t) ++ A [I] [getint ()]; for1 (J, 1, n) A [I] [J] % = 7 ;} int ans = Gauss (a, m, n, 7); If (ANS =-1) puts ("inconsistent data. "); else if (ANS) puts (" multiple solutions. "); else {for1 (I, 1, n) if (a [I] [n + 1] <3) A [I] [n + 1] + = 7; for1 (I, 1, n-1) printf ("% d", a [I] [n + 1]); printf ("% d \ n ", a [n] [n + 1]);} n = getint (), M = getint ();} return 0 ;}

  

 

 

 

Description

The widget factory produces several different kinds of widgets. each widget is carefully built by a skilled widgeteer. the time required to build a widget depends on its type: the simple widgets need only 3 days, but the most complex ones may need as stored as 9 days.

The factory is currently in a state of complete chaos: Recently, the factory has been bought by a new owner, and the new director has fired almost everyone. the new staff know almost nothing about building widgets, and it seems that no one remembers how many days are required to build each diofferent type of widget. this is very embarrassing when a client orders widgets and the factory cannot tell the client how many days are needed to produce the required goods. fortunately, there are records that say for each widgeteer the date when he started working at the factory, the date when he was fired and what types of widgets he built. the problem is that the record does not say the exact date of starting and leaving the job, only the day of the week. nevertheless, even this information might be helpful in certain cases: for example, if a widgeteer started working on a Tuesday, built a type 41 widget, and was fired on a Friday, then we know that it takes 4 days to build a type 41 widget. your task is to figure out from these records (if possible) the number of days that are required to build the different types of widgets.

Input

The input contains several blocks of test cases. each case begins with a line containing two integers: The number 1 ≤ n ≤ 300 of the Different types, and the Number 1 ≤ m ≤ 300 of the records. this line is followed by a description of the M records. each record is described by two lines. the first line contains the total number 1 ≤ k ≤ 10000 of widgets built by this widgeteer, followed by the day of week when he/she started working and the day of the week he/she was fired. the days of the week are given bythe strings 'mon', 'tue ', 'wed', 'thu', 'fri', 'sat' and 'sun '. the second line contains k integers separated by spaces. these numbers are between 1 and N, and they describe the diofferent types of widgets that the widgeteer built. for example, the following two lines mean that the widgeteer started working on a Wednesday, built a type 13 widget, a type 18 widget, a type 1 widget, again a type 13 widget, and was fired on a Sunday.

4 wed sun
13 18 1 13

Note that the widgeteers work 7 days a week, and they were working on every day between their first and last day at the factory (if you like weekends and holidays, then do not become a widgeteer !).

The input is terminated by a test case with N = m = 0.

Output

For each test case, you have to output a single line containing N integers separated by spaces: the number of days required to build the different types of widgets. there shoshould be no space before the first number or after the last number, And There shoshould be exactly one space between two numbers. if there is more than one possible solution for the problem, then write 'Multiple solutions. '(without the quotes ). if you are sure that there is no solution consistent with the input, then write 'inconsistent data. '(without the quotes ).

Sample Input

2 32 MON THU1 23 MON FRI1 1 23 MON SUN1 2 210 21 MON TUE 31 MON WED30 0

Sample output

8 3Inconsistent data.

Hint

Huge input file, 'scanf' recommended to avoid TLE.

Source

Central Europe 2005

[Poj] 2947 widget Factory (Gaussian deyuan)

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.