题目连接:

  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. Spring MVC 异步处理请求,提高程序性能

    原文:http://blog.csdn.net/he90227/article/details/52262163 什么是异步模式 如何在Spring MVC中使用异步提高性能? 一个普通 Servle ...

  2. linux 中断机制浅析

    一.中断相关结构体 1.irq_desc中断描述符 struct irq_desc { #ifdef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED struct irq_ ...

  3. 解决java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException

    解决: 工程目录.settings\org.eclipse.wst.common.project.facet.core.xml文件中jst.web的version降低到2.5 <?xml ver ...

  4. es5~es6

    1.用箭头函数减少代码(相信你在Vue已经看到了) ES5: function greetings (name) { return 'hello ' + name } ES6: const greet ...

  5. 各项异性滤波简单介绍Anisotropic Filtering(AF)

    本文主要整理简绍来自互联网的各项异性滤波的知识. 原文链接:http://www.linuxgraphics.cn/graphics/using_anisotropic_texture_filteri ...

  6. win7-64bit安装comtypes的问题

    Update 28/12/2014: Please download the latest comtypes 1.1.1 from https://pypi.python.org/pypi/comty ...

  7. jQuery的AJax异步訪问

    用一个样例用以说明:点击button,将input内用户输入的数据发送给服务端.并将结果返回给页面. 首先是html承载内容: <!DOCTYPE html> <html> & ...

  8. 6.游戏特别离不开脚本(3)-JS脚本操作java(直接解析JS公式,并非完整JS文件或者函数)

    engine.put("usList", us); engine.put("obj", new JSModifiedJava()) ;  取个变量名就put进去 ...

  9. caioj1097: [视频]树状数组1(快速求和计算) cdq分治入门

    这题虽然是个树状数组,但是也可以用cdq分治做啊~~,这个就是一个浅显的二维偏序的应用? cdq分治和普通的分治有什么区别? 举个栗子:有4个小朋友,你请他们吃饭,假如你分治搞,就会分成很多子问题—— ...

  10. Ubuntu如何定时清理内存

    Ubuntu如何定时清理内存 1.进入su jiqing@Ubuntu:~$ su 密码: root@Ubuntu:/home/jiqing# 2.创建cleanCache.sh #!/bin/bas ...