POJ2947——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

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

这题就是给你一个有m个方程,有n个变量的方程组,然后求解。
每个方程形如  x[i]*mat[k][i] + x[i+1]*mat[k][i+1] + .....  =t[k](mod 7)
那么就可以用高斯消元来解决了, 注意要不断地对7取余。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>

using namespace std;

const int maxn=340;
const int MOD=7;
int x[maxn];
int mat[maxn][maxn];
int free_x[maxn];

int gcd(int a,int b)
{
int t;
while(b)
{
t=b;
b=a%b;
a=t;
}
return a;
}

int lcm(int a,int b)
{
return a/gcd(a,b)*b;
}

int Gauss(int equ,int var)
{
memset(x,0,sizeof(x));
memset(free_x,1,sizeof(x));
int i,j,k;
int max_r;
int col,free_index,free_num,ta,tb,temp,LCM;
for(k=0,col=0;k<equ && col<var;k++,col++)
{
max_r=k;
for(i=k+1;i<equ;i++)
{
if(abs(mat[i][col]) > abs(mat[max_r][col]))
max_r=i;
}
if(max_r != k)
{
for(i=k;i<var+1;i++)
swap(mat[k][i],mat[max_r][i]);
}
if(mat[k][col] == 0)
{
k--;
continue;
}
for(i=k+1;i<equ;i++)
{
if(mat[i][col])
{
LCM=lcm(abs(mat[k][col]),abs(mat[i][col]));
ta=LCM/abs(mat[i][col]);
tb=LCM/abs(mat[k][col]);
if(mat[i][col] * mat[k][col] < 0)
tb=-tb;
for(j=col;j<var+1;j++)
mat[i][j]=((mat[i][j]*ta-mat[k][j]*tb)%MOD + MOD)%MOD;
}
}
}
for(i=k;i<equ;i++)
if(mat[i][col])
return -1;
if(var > k)
return var-k;
//回代
for(i=var-1;i>=0;i--)
{
temp=mat[i][var];
for(j=i+1;j<var;j++)
if(mat[i][j])
{
temp-=mat[i][j]*x[j];
temp=(temp%MOD+MOD)%MOD;
}
while (temp % mat[i][i] != 0) temp+=MOD;
x[i]=(temp/mat[i][i])%MOD;
}
return 0;
}

char str1[10],str2[10];

int main()
{
int n,m,k,d;
map<string,int>times;
times["MON"]=1;
times["TUE"]=2;
times["WED"]=3;
times["THU"]=4;
times["FRI"]=5;
times["SAT"]=6;
times["SUN"]=7;
while(~scanf("%d%d",&n,&m))
{
if(!n && !m)
break;
memset(mat,0,sizeof(mat));
for(int i=0;i<m;i++)
{
scanf("%d%s%s",&k,str1,str2);
mat[i][n]=((times[str2]-times[str1]+1)%MOD+MOD)%MOD;
for(int j=1;j<=k;j++)
{
scanf("%d",&d);
d--;
mat[i][d]++;
mat[i][d]%=7;
}
}
int res=Gauss(m,n);
if(res==-1)
printf("Inconsistent data.\n");
else if(res>0)
printf("Multiple solutions.\n");
else
{
for(int i=0;i<n-1;i++)
{
if(x[i]<3)
x[i]+=MOD;
printf("%d ",x[i]);
}
if(x[n-1]<3)
x[n-1]+=MOD;
printf("%d\n",x[n-1]);
}
}
return 0;
}




标题基于SpringBoot+Vue的社区便民服务平台研究AI更换标题第1章引言介绍社区便民服务平台的研究背景、意义,以及基于SpringBoot+Vue技术的研究现状和创新点。1.1研究背景与意义分析社区便民服务的重要性,以及SpringBoot+Vue技术在平台建设中的优势。1.2国内外研究现状概述国内外在社区便民服务平台方面的发展现状。1.3研究方法与创新点阐述本文采用的研究方法和在SpringBoot+Vue技术应用上的创新之处。第2章相关理论介绍SpringBoot和Vue的相关理论基础,以及它们在社区便民服务平台中的应用。2.1SpringBoot技术概述解释SpringBoot的基本概念、特点及其在便民服务平台中的应用价值。2.2Vue技术概述阐述Vue的核心思想、技术特性及其在前端界面开发中的优势。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue如何有效整合,以提升社区便民服务平台的性能。第3章平台需求分析与设计分析社区便民服务平台的需求,并基于SpringBoot+Vue技术进行平台设计。3.1需求分析明确平台需满足的功能需求和性能需求。3.2架构设计设计平台的整体架构,包括前后端分离、模块化设计等思想。3.3数据库设计根据平台需求设计合理的数据库结构,包括数据表、字段等。第4章平台实现与关键技术详细阐述基于SpringBoot+Vue的社区便民服务平台的实现过程及关键技术。4.1后端服务实现使用SpringBoot实现后端服务,包括用户管理、服务管理等核心功能。4.2前端界面实现采用Vue技术实现前端界面,提供友好的用户交互体验。4.3前后端交互技术探讨前后端数据交互的方式,如RESTful API、WebSocket等。第5章平台测试与优化对实现的社区便民服务平台进行全面测试,并针对问题进行优化。5.1测试环境与工具介绍测试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值