POJ 2947 Widget Factory(高斯消元)
Description
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
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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std; int inv[]; struct MOD7 {
int val;
MOD7() {}
MOD7(int val): val((val + ) % ) {}
MOD7 operator + (const MOD7 &rhs) const {
return MOD7(val + rhs.val);
}
MOD7 operator - (const MOD7 &rhs) const {
return MOD7(val - rhs.val);
}
MOD7 operator * (const MOD7 &rhs) const {
return MOD7(val * rhs.val);
}
MOD7 operator / (const MOD7 &rhs) const {
return MOD7(val * inv[rhs.val]);
}
void operator -= (const MOD7 &rhs) {
val = (val - rhs.val + ) % ;
}
bool isZero() {
return val == ;
}
void inc() {
val = (val + ) % ;
}
void print() {
if(val < ) printf("%d", val + );
else printf("%d", val);
}
}; map<string, int> mymap; void init() {
for(int i = ; i < ; ++i) {
inv[i] = ;
for(int j = ; j < ; ++j) inv[i] = (inv[i] * i) % ;
}
mymap["MON"] = ;
mymap["TUE"] = ;
mymap["WED"] = ;
mymap["THU"] = ;
mymap["FRI"] = ;
mymap["SAT"] = ;
mymap["SUN"] = ;
} const int MAXN = ; MOD7 mat[MAXN][MAXN];
int n, m; int guess_eliminatioin() {
int rank = ;
for(int i = , t = ; i < m && t < n; ++i, ++t) {
int r = i;
for(int j = i + ; j < m; ++j)
if(mat[r][t].val < mat[j][t].val) r = j;
if(mat[r][t].isZero()) { --i; continue;}
else ++rank;
if(r != i) for(int j = ; j <= n; ++j) swap(mat[i][j], mat[r][j]);
for(int j = n; j >= t; --j)
for(int k = i + ; k < m; ++k) mat[k][j] -= mat[i][j] * mat[k][t] / mat[i][t];
}
for(int i = rank; i < m; ++i)
if(!mat[i][n].isZero()) return -;
if(rank < n) return ;
for(int i = n - ; i >= ; --i) {
for(int j = i + ; j < n; ++j)
mat[i][n] -= mat[j][n] * mat[i][j];
mat[i][n] = mat[i][n] / mat[i][i];
}
return ;
} int main() {
init();
while(scanf("%d%d", &n, &m) != EOF) {
if(n == && m == ) break;
memset(mat, , sizeof(mat));
int t, p;
string s1, s2;
for(int i = ; i < m; ++i) {
cin>>t>>s1>>s2;
while(t--) {
scanf("%d", &p);
mat[i][p - ].inc();
}
mat[i][n] = MOD7(mymap[s2] - mymap[s1] + );
}
int result = guess_eliminatioin();
if(result == -) puts("Inconsistent data.");
else if(result == ) puts("Multiple solutions.");
else {
for(int i = ; i < n - ; ++i) {
mat[i][n].print();
putchar(' ');
}
mat[n - ][n].print();
puts("");
}
}
}
POJ 2947 Widget Factory(高斯消元)的更多相关文章
- Poj 2947 widget factory (高斯消元解同模方程)
题目连接: http://poj.org/problem?id=2947 题目大意: 有n种类型的零件,m个工人,每个零件的加工时间是[3,9],每个工人在一个特定的时间段内可以生产k个零件(可以相同 ...
- POJ 2947 2947 Widget Factory 高斯消元
给出组件的数量n,给出记录的数量m(n就是变元数量,m是方程数量).每一个记录代表一个方程,求每个组件的生产天数. 高斯消元即可 #include <cstdio> #include &l ...
- POJ 2947-Widget Factory(高斯消元解同余方程式)
题目地址:id=2947">POJ 2947 题意:N种物品.M条记录,接写来M行,每行有K.Start,End,表述从星期Start到星期End,做了K件物品.接下来的K个数为物品的 ...
- POJ2947Widget Factory(高斯消元解同模方程)
http://poj.org/problem?id=2947 题目大意:有n 种装饰物,m 个已知条件,每个已知条件的描述如下:p start enda1,a2......ap (1<=ai&l ...
- poj 2947 Widget Factory
Widget Factory 题意:有n件装饰品,有m组信息.(1 <= n ,m<= 300)每组信息有开始的星期和结束的星期(是在mod 7范围内的)并且还包括num种装饰品的种类(1 ...
- POJ 1830 开关问题 高斯消元,自由变量个数
http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...
- A - The Water Bowls POJ - 3185 (bfs||高斯消元)
题目链接:https://vjudge.net/contest/276374#problem/A 题目大意:给你20个杯子,每一次操作,假设当前是对第i个位置进行操作,那么第i个位置,第i+1个位置, ...
- POJ 1166 The Clocks 高斯消元 + exgcd(纯属瞎搞)
依据题意可构造出方程组.方程组的每一个方程格式均为:C1*x1 + C2*x2 + ...... + C9*x9 = sum + 4*ki; 高斯消元构造上三角矩阵,以最后一个一行为例: C*x9 = ...
- POJ 2065 SETI(高斯消元)
题目链接:http://poj.org/problem?id=2065 题意:给出一个字符串S[1,n],字母a-z代表1到26,*代表0.我们用数组C[i]表示S[i]经过该变换得到的数字.给出一个 ...
随机推荐
- Day09
Servlet概述 生命周期方法: void init(ServletConfig):出生之后(1次): void service(ServletRequest request, ServletRes ...
- Bluetooth Baseband介绍
目录 1. 概述 1.1 Clock(时钟) 1.2 寻址方式 2. 物理信道(Physical Channels) 3. 物理链路(Physical Links) 4. 逻辑传输层(Logical ...
- LMAO?
70 weeks to finish TC problems? 2015.4.16 week1 week1~week8:Graph 1.DFS,BFS,Topological sort,Strongl ...
- Unicode与UTF8相互转化(使用MultiByteToWideChar)
1.简述 最近在发送网络请求时遇到了中文字符乱码的问题,在代码中调试字符正常,用抓包工具抓的包中文字符显示正常,就是发送到服务器就显示乱码了,那就要将客户端和服务器设置统一的编码(UTF-8),而我们 ...
- RelativeLayout不能调用measure去直接测量子元素
RelativeLayout在实现onMeasure方法时并没有像LinearLayout一样去重写如下代码: @Override protected void onMeasure(int width ...
- CSS控制"标题前增加小图标或编号"
---题目前加图片--- p:before { content:url(xxx/xx.png); }//所有p的最前都有一个图标 p.a:after { content:url(xxx/xx.png) ...
- ArcGIS API for Silverlight 实现修改地图上的工程点位置
原文:ArcGIS API for Silverlight 实现修改地图上的工程点位置 #region 处理工程点点击编辑相关事件 public Graphic editgraphics = null ...
- js数组到后台转 list数组
前台的数组格式是: [{"credit_record_certificate_id":"452","credit_record_type": ...
- postgresql 将查询结果导出到文件
方法1:进入查询终端,输入\o aa.out 查询结果将输出到当前目录的aa.out 文件 方法2: 将查询语句写a.sql中, alias sql2="export PGPASSWORD ...
- mysql导入导出
1.导入整个库 进入数据库,source 进去的语句等同于直接连接数据库后数据的语句 >source /var/www/test.sql 或者 sy$ mysql -uroot -p 数据库名( ...