题目连接:

  http://poj.org/problem?id=2947

题目大意:

  有n种类型的零件,m个工人,每个零件的加工时间是[3,9],每个工人在一个特定的时间段内可以生产k个零件(可以相同种类,也可以不同种类),问每种零件生产一个出来需要的时间?

解题思路:

  给出的时间段是从周几到周几,并没有给出具体的时间段,因此在计算过程中要进行取模,还有就是对每个零件要在题目要求的范围内进行枚举。

ps:如果求出来的增广矩阵是n*n的,但是某个零件在[3,9]之间没有合理的解,也是无解的。

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = ;
int det[maxn][maxn], res[maxn], var, equ;
char str[][] = {"","MON", "TUE", "WED", "THU", "FRI", "SAT" , "SUN"};
int Day (char s[])
{
for (int i=; i<; i++)
if (strcmp(s, str[i]) == )
return i;
}
int gauss ()
{
int col, k;
for (k=col=; k<equ&&col<var; k++, col++)
{
int Max_i = k;
for (int i=k+; i<equ; i++)
if (abs(det[i][col]) > abs(det[Max_i][col]))
Max_i = i;
if (Max_i != k)
for (int i=col; i<=var; i++)
swap (det[k][i], det[Max_i][i]);
if (det[k][col] == )
{
k --;
continue;
}
for (int i=k+; i<equ; i++)
if (det[i][col])
{
int x = det[i][col];
int y = det[k][col];
for (int j=col; j<=var; j++)
det[i][j] = ((det[i][j]*y - det[k][j]*x) % + ) % ;
}
}
int temp = , i, j;
for (i=; i<equ; i++)
{
for (j=; j<var; j++)
if (det[i][j])
break;
if (j == var)
{
if (det[i][j])
return ;//增广矩阵无解
else if (i < var)//增广矩阵存在不确定变元
temp ++;
}
}
if (temp || var > equ)
return ;//增广矩阵存在不确定变元 for (i=var-; i>=; i--)
{
temp = ;
for (j=i+; j<var; j++)
temp = (temp + det[i][j] * res[j]) % ;
for (j=; j<; j++)//枚举每个零件的加工时长
if ((temp + det[i][i]*j)% == det[i][var])
{
res[i] = j;
break;
}
if (j == )//当有某个零件的加工时长不在[3,9]之间,则不符合题意,无解
return ;
}
return ;
}
int main ()
{
while (scanf ("%d %d", &var, &equ), var+equ)
{
int k, x;
char st[maxn], et[maxn];
memset (det, , sizeof(det));
for (int i=; i<equ; i++)
{
scanf ("%d %s %s", &k, st, et);
while (k --)
{
scanf ("%d", &x);
det[i][x-] ++;
}
det[i][var] = Day(et) - Day(st) + ;
}
for (int i=; i<equ; i++)//这里一定要去次余,如果det[i][j]是7的倍数,在划成阶梯阵的过程中很有可能会错
for (int j=; j<=var; j++)
det[i][j] = (det[i][j] % + ) % ;
int ans = gauss();
if (ans == )
printf ("Inconsistent data.\n");
else if (ans == )
printf ("Multiple solutions.\n");
else
for (int i=; i<var; i++)
printf ("%d%c", res[i], i==var-?'\n':' ');
}
return ;
}

Poj 2947 widget factory (高斯消元解同模方程)的更多相关文章

  1. POJ 2947 2947 Widget Factory 高斯消元

    给出组件的数量n,给出记录的数量m(n就是变元数量,m是方程数量).每一个记录代表一个方程,求每个组件的生产天数. 高斯消元即可 #include <cstdio> #include &l ...

  2. POJ2947Widget Factory(高斯消元解同模方程)

    http://poj.org/problem?id=2947 题目大意:有n 种装饰物,m 个已知条件,每个已知条件的描述如下:p start enda1,a2......ap (1<=ai&l ...

  3. POJ 2947-Widget Factory(高斯消元解同余方程式)

    题目地址:id=2947">POJ 2947 题意:N种物品.M条记录,接写来M行,每行有K.Start,End,表述从星期Start到星期End,做了K件物品.接下来的K个数为物品的 ...

  4. POJ 2947 Widget Factory(高斯消元)

    Description The widget factory produces several different kinds of widgets. Each widget is carefully ...

  5. poj2947(高斯消元解同模方程组)

    题目链接:http://poj.org/problem?id=2947 题意:有n 种装饰物,m 个已知条件,每个已知条件的描述如下: p start enda1, a2......ap (1< ...

  6. poj1830(高斯消元解mod2方程组)

    题目链接:http://poj.org/problem?id=1830 题意:中文题诶- 思路:高斯消元解 mod2 方程组 有 n 个变元,根据给出的条件列 n 个方程组,初始状态和终止状态不同的位 ...

  7. poj1753(高斯消元解mod2方程组)

    题目链接:http://poj.org/problem?id=1753 题意:一个 4*4 的棋盘,初始时上面放满了黑色或白色的棋子.对 (i, j) 位置进行一次操作后 (i, j), (i + 1 ...

  8. bzoj千题计划187:bzoj1770: [Usaco2009 Nov]lights 燈 (高斯消元解异或方程组+枚举自由元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1770 a[i][j] 表示i对j有影响 高斯消元解异或方程组 然后dfs枚举自由元确定最优解 #in ...

  9. [置顶] hdu 4418 高斯消元解方程求期望

    题意:  一个人在一条线段来回走(遇到线段端点就转变方向),现在他从起点出发,并有一个初始方向, 每次都可以走1, 2, 3 ..... m步,都有对应着一个概率.问你他走到终点的概率 思路: 方向问 ...

随机推荐

  1. Duplicate property mapping of contactPhone found in

    启动的时候报Duplicate property mapping of contactPhone found in com....的错误,是因为在建立实体对象的时候,有字段重复了,有的是继承了父类的字 ...

  2. css中使input输入框与img(图片)在同一行居中对齐

    input,img{vertical-align:middle;},同时设置input和img的vertical-align属性,兼容ie7

  3. HDU 2896 病毒侵袭 (AC自己主动机)

    pid=2896">http://acm.hdu.edu.cn/showproblem.php?pid=2896 病毒侵袭 Time Limit: 2000/1000 MS (Java ...

  4. eclipse maven 插件的安装和配置

    maven3 安装: 安装 Maven 之前要求先确定你的 JDK 已经安装配置完毕.Maven是 Apache 下的一个项目.眼下最新版本号是 3.0.4.我用的也是这个. 首先去官网下载 Mave ...

  5. 可用内存free不足 hadoop3 无法启动 手动释放缓存 cache

    [root@hadoop3 hadoop]# xlfg total used free shared buff/cache availableMem: 15 0 2 0 12 14Swap: 7 0 ...

  6. Codeforces Round #261 (Div. 2)——Pashmak and Graph

    题目链接 题意: n个点.m个边的有向图.每条边有一个权值,求一条最长的路径,使得路径上边值严格递增.输出路径长度 )) 分析: 由于路径上会有反复点,而边不会反复.所以最開始想的是以边为状态进行DP ...

  7. nextLine() 、nextInt()的跳过问题

    nextInt()  将输入的信息的下一个标记扫描为 int. nextLine() 此扫描器执行当前行,并返回跳过的输入信息. nextInt 会读取下面输入的 int类型的信息以回车作为结束,如果 ...

  8. SoapUI中读取Office365邮件

    常见邮件服务一般使用IMAP邮件访问协议,如果你所在公司更换到Office 365则需要另一个组件. Office 365使用的是Exchange Server电子邮件服务组件,需要微软的Jar包来支 ...

  9. HTML表单常用标签

    名称 用例 备注 文本输入框             <input type="text" name="uname" value="" ...

  10. 性能测试工具curl-loader(linux)

    curl-loader介绍 curl-loader(也被称为“omes-NIK”和“davilka”)是一个开源的C语言编写的工具,模拟应用负载和成千上万的几十万人的HTTP / HTTPS和FTP/ ...