poj 2947 Widget Factory(高斯消元)
2013-08-14 21:44
483 查看
Widget Factory
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 many 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 should be no space before the first number or after the last number, and there should
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
Sample Output
Hint
Huge input file, 'scanf' recommended to avoid TLE.
Source
Central Europe 2005
题解:利用高斯消元求方程就可以了
Time Limit: 7000MS | Memory Limit: 65536K | |
Total Submissions: 4032 | Accepted: 1337 |
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 many 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 should be no space before the first number or after the last number, and there should
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 3 2 MON THU 1 2 3 MON FRI 1 1 2 3 MON SUN 1 2 2 10 2 1 MON TUE 3 1 MON WED 3 0 0
Sample Output
8 3 Inconsistent data.
Hint
Huge input file, 'scanf' recommended to avoid TLE.
Source
Central Europe 2005
题解:利用高斯消元求方程就可以了
#include<stdio.h> #include<string.h> #include<stdlib.h> int a[303][303],cc[303],n,m; int change(char *s) { if(strcmp(s,"MON")==0) return 1; else if(strcmp(s,"TUE")==0) return 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; return 7; } void gauss() { int i,j,k,l,o,x,y; memset(cc,0,sizeof(cc)); for(i=j=0; i<m&&j<n; j++) { for(k=i; k<m; k++) if(a[k][j]) break; if(a[k][j]) { for(l=j; l<=n; l++) { x=a[k][l]; a[k][l]=a[i][l]; a[i][l]=x; } for(l=0; l<m; l++) { if(l!=i&&a[l][j]) { x=a[i][j],y=a[l][j]; for(o=0; o<=n; o++) a[l][o]=((a[l][o]*x-a[i][o]*y)%7+7)%7; } } i++; } } for(j=i; j<m; j++) { if(a[j] ) { printf("Inconsistent data.\n"); return; } } if(i<n) { printf("Multiple solutions.\n"); return; } for(i=n-1;i>=0;i--) { x=a[i] ; for(j=i+1;j<n;j++) x=((x-a[i][j]*cc[j])%7+7)%7; while(x%a[i][i]!=0) x+=7; cc[i]=(x/a[i][i])%7; } for(i=0;i<n;i++) if(cc[i]<3) cc[i]+=7; for(i=0;i<n-1;i++) printf("%d ",cc[i]); printf("%d\n",cc[i]); } int main() { int i,j,x,y; char s1[8],s2[8]; freopen("t.txt","r",stdin); while(scanf("%d%d",&n,&m)&&n+m) { memset(a,0,sizeof(a)); for(i=0; i<m; i++) { scanf("%d",&x); scanf("%s%s",s1,s2); a[i] =(change(s2)-change(s1)+1+7)%7; while(x--) { scanf("%d",&y); a[i][y-1]++; } for(j=0; j<n; j++) a[i][j]%=7; } gauss(); } return 0; }
相关文章推荐
- poj 2947 Widget Factory (高斯消元)
- poj 2947 Widget Factory (高斯消元)
- poj 2947 Widget Factory(高斯消元)
- POJ 2947 Widget Factory(高斯消元)
- Poj 2947 widget factory (高斯消元解同模方程)
- poj 2947 Widget Factory (高斯消元,解模线性方程)
- POJ 2947 Widget Factory 高斯消元
- poj -- 2947 Widget Factory(高斯消元)
- 文章标题 POJ 2947 : Widget Factory (高斯消元)
- POJ 2947-Widget Factory(高斯消元解同余方程式)
- poj2947——Widget Factory(高斯消元求模线性方程)
- POJ 2947 Widget Factory(高斯消元)
- POJ 2947 Widget Factory(取模的高斯消元)
- POJ 2947 Widget Factory(高斯消元解同余方程组)
- POJ 2947 Widget Factory(高斯消元)
- poj 2947 Widget Factory(数学:高斯消元)
- poj 2947 Widget Factory (高斯消元)
- poj 2947 Widget Factory(模7环上的高斯消元)
- POJ 2947 Widget Factory (高斯消元 判多解 无解 和解集 模7情况)
- POJ 2947-Widget Factory(高斯消元解同余方程式)