POJ Widget Factory 【求解模线性方程】

开源AI工具链实战:本地化部署与高效微调指南 大模型技术正从云端API走向本地化部署与自主可控的工程实践。理解模型量化、LoRA微调、RAG编排等核心原理,是实现低成本、低延迟、高合规AI应用的关键。开源工具链如llama.cpp、Ollama、Unsloth和LlamaIndex,通过标准化接口与模块化设计,显著降低了大模型在边缘设备、中小企业及垂直场景中的落地门槛。本文聚焦真实项目中的性能调优、许可证合规、显存管理与方言适配等硬核细节,为开发者提供可复现、可审计、可交付的开源AI工程路径。 阅读详情

传送门:http://poj.org/problem?id=2947

Widget Factory

Time Limit: 7000MS Memory Limit: 65536K
Total Submissions: 7109 Accepted: 2496

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

 

 

题意概括:

给N种零件,M次工人的工作记录,每次记录包括 该工人处理了的零件数 、星期几开始 和 星期几结束(可能相隔很多个星期)。求制造每种零件所需要的时间。

 

解题思路:

N种零件就是N个未知数,M次操作就是M个方程。

根据M次操作构造出增广矩阵,高斯消元,不过求解过程要加上取模操作;

最后输出答案是特判一下答案是否小于等于2,如果是需要+7,因为我们运算的时候是取模运算,根据题意可知零件加工天数范围在【3,9】;

 

AC code:

  1 #include <cstdio>
  2 #include <iostream>
  3 #include <algorithm>
  4 #include <cstring>
  5 #include <cmath>
  6 #define INF 0x3f3f3f3f
  7 using namespace std;
  8 const int MAXN = 333;
  9 
 10 int a[MAXN][MAXN];//增广矩阵
 11 int x[MAXN];//解集
 12 bool free_x[MAXN];//标记是否是不确定的变元
 13 
 14 inline int gcd(int a,int b)                 //最大公约数
 15 {
 16     int t;
 17     while(b!=0)
 18     {
 19         t=b;
 20         b=a%b;
 21         a=t;
 22     }
 23     return a;
 24 }
 25 
 26 inline int lcm(int a,int b)                 //最小公倍数
 27 {
 28     return a/gcd(a,b)*b;                    //先除后乘防溢出
 29 }
 30 
 31 int Gauss(int equ,int var)
 32 {
 33     int i,j,k;
 34     int max_r;// 当前这列绝对值最大的行.
 35     int col;//当前处理的列
 36     int ta,tb;
 37     int LCM;
 38     int temp;
 39     int free_x_num;
 40     int free_index;
 41 
 42     for(int i=0;i<=var;i++)
 43     {
 44         x[i]=0;
 45         free_x[i]=true;
 46     }
 47 
 48     //转换为阶梯阵.
 49     col=0; // 当前处理的列
 50     for(k = 0;k < equ && col < var;k++,col++)
 51     {// 枚举当前处理的行.
 52 // 找到该col列元素绝对值最大的那行与第k行交换.(为了在除法时减小误差)
 53         max_r=k;
 54         for(i=k+1;i<equ;i++)
 55         {
 56             if(abs(a[i][col])>abs(a[max_r][col])) max_r=i;
 57         }
 58         if(max_r!=k)
 59         {// 与第k行交换.
 60             for(j=k;j<var+1;j++) swap(a[k][j],a[max_r][j]);
 61         }
 62         if(a[k][col]==0)
 63         {// 说明该col列第k行以下全是0了,则处理当前行的下一列.
 64             k--;
 65             continue;
 66         }
 67         for(i=k+1;i<equ;i++)
 68         {// 枚举要删去的行.
 69             if(a[i][col]!=0)
 70             {
 71                 LCM = lcm(abs(a[i][col]),abs(a[k][col]));
 72                 ta = LCM/abs(a[i][col]);
 73                 tb = LCM/abs(a[k][col]);
 74                 if(a[i][col]*a[k][col]<0)tb=-tb;//异号的情况是相加
 75                 for(j=col;j<var+1;j++)
 76                 {
 77                     a[i][j] = ((a[i][j]*ta-a[k][j]*tb)%7+7)%7;
 78                 }
 79             }
 80         }
 81     }
 82 
 83     // 1. 无解的情况: 化简的增广阵中存在(0, 0, ..., a)这样的行(a != 0).
 84     for (i = k; i < equ; i++)
 85     { // 对于无穷解来说,如果要判断哪些是自由变元,那么初等行变换中的交换就会影响,则要记录交换.
 86         if ( a[i][col]  != 0) return -1;
 87     }
 88 
 89     if (k < var)
 90     {
 91         return var - k; // 自由变元有var - k个.
 92     }
 93     // 3. 唯一解的情况
 94     // 计算出Xn-1, Xn-2 ... X0.
 95     for (i = var - 1; i >= 0; i--)
 96     {
 97         temp = a[i][var];
 98         for (j = i + 1; j < var; j++)
 99         {
100             if (a[i][j] != 0) temp -= a[i][j] * x[j];
101             temp=(temp%7+7)%7;
102         }
103         while (temp % a[i][i] != 0) temp+=7;
104         x[i] =( temp / a[i][i])%7 ;
105     }
106     return 0;
107 }
108 
109 int sts(char *s)
110 {
111     if(strcmp(s, "MON") == 0) return 1;
112     else if(strcmp(s, "TUE") == 0) return 2;
113     else if(strcmp(s, "WED") == 0) return 3;
114     else if(strcmp(s, "THU") == 0) return 4;
115     else if(strcmp(s, "FRI") == 0) return 5;
116     else if(strcmp(s, "SAT") == 0) return 6;
117     else if(strcmp(s, "SUN") == 0) return 7;
118 }
119 
120 int main()
121 {
122     int N, M, xx, t;
123     char str1[10], str2[10];
124     while(~scanf("%d%d", &N, &M) && (N+M)){
125         memset(a, 0, sizeof(a));
126         for(int i = 0; i < M; i++){
127             scanf("%d%s%s", &xx, str1, str2);
128             a[i][N] = ((sts(str2)-sts(str1)+1)%7+7)%7;
129 
130             for(int j = 0; j < xx; j++){
131                 scanf("%d", &t);
132                 t--;
133                 a[i][t]++;
134                 a[i][t] = a[i][t]%7;
135             }
136         }
137         int ans = Gauss(M, N);
138         if(ans == -1) puts("Inconsistent data.");
139         else if(ans == 0){
140             for(int i = 0; i < N-1; i++){
141                 if(x[i] <= 2) printf("%d ", x[i]+7);
142                 else printf("%d ", x[i]);
143             }
144             if(x[N-1] <= 2) printf("%d\n", x[N-1]+7);
145             else printf("%d\n", x[N-1]);
146         }
147         else{
148             puts("Multiple solutions.");
149         }
150     }
151     return 0;
152 }
View Code

 

浙江大学Fast-Lab从0制作自主空中机器人公开课教程补充及部分注意事项(适用于ubuntu系统和ROS零基础) 浙江大学Fast-Lab从0制作自主空中机器人公开课纯萌新补充(适用于从没接触过ubuntu系统),记录了一些自己不会的地方以及踩过的坑 阅读详情

相关推荐

mipi deskew原理理解

何为skew, 从字面意思看是倾斜了,不对齐了;放在mipi的传输中意思就是clock lane和data lane 及data lane与data lane间出现了相位差;一旦出现相位差,大家采样数据时就可能不在同一个节拍上,会出现传输错误。所以就要做deskew,通过做deskew来使得大家重新对齐,在同一个节奏下传输数据. 一般当data rate高于1.5G时建议开启deskew。

lx123010的专栏 8105

部件库(Widget Factory)

部件库(Widget Factory)是一个强大的工具,它为开发者提供了丰富的UI组件和高度的可定制性。通过使用部件库,开发者可以大大提高开发效率,同时创建出美观、响应式的用户界面。无论是Web应用、移动应用,还是原型设计和UI/UX设计,部件库都能够提供强大的支持。

lly202406的博客 457

Playwright与MCP协议结合:AI驱动的智能Web自动化测试实践

Web自动化测试是现代软件开发流程中保障产品质量的关键环节,其核心原理是通过程序模拟用户操作,对Web应用进行功能验证。传统自动化测试工具如Selenium和Playwright虽然提供了强大的API,但脚本编写和维护仍需较高的编程技能。随着AI技术的发展,智能测试成为新的趋势,它通过自然语言理解和自动化执行,显著降低了测试创建门槛。Model Context Protocol(MCP)作为一种连接AI模型与外部工具的开放协议,为自动化测试带来了“智能大脑”。通过将MCP与Playwright结合,测试人员

aoe41606的博客 606

jQuery UI 如何使用部件库(Widget Factory)

我们将创建一个进度条。正如下面实例所示,这可以通过调用来完成,它带有两个参数:一个是要创建的插件名称,一个是包含支持插件的函数的对象文字。当插件被调用时,它将创建一个新的插件实例,所有的函数都将在该实例的语境中被执行。这与两种重要方式的标准 jQuery 插件不同。首先,语境是一个对象,不是 DOM 元素。其次,语境总是一个单一的对象,不是一个集合。});插件的名称必须包含命名空间,在这个实例中,我们使用了custom命名空间。您只能创建一层深的命名空间,因此,是一个有效的插件名称,而。

unber的博客 417

【Python爬虫案例教学】超简洁代码采集原神所有角色信息

(。・∀・)ノ゙嗨 大家好,这里是池鱼

xiaoyuan_____的博客 2421

扩视机器视觉—Halcon机器视觉48个实战项目六(检测定位角度)

此项目halcon检测检测定位角度问题,并显示。

qq_21516871的博客 1097

poj 2947 Widget Factory(高斯消元)

Widget Factory Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 4032   Accepted: 1337 Description The widget factory produces several different kinds of wid

街角的花街糖 1151

反激开关电源变压器设计实例讲解(定明芳)

内容来自《反激变压器的设计》(定明芳主讲)。 定名芳老师主要讲了10步,最后应该还有一步,线径的选择已经绕制方式。这里进行了记录整理,把一些公式来源进行了推导。所有的设计都是基于理论计算。 1.确定电源规格 2.确定工作频率和最大占空比 3.计算匝比(利用伏秒平衡原则) 此处插入解释一下伏秒平衡,根源是磁通量平衡。该原则可以用来检查MOS管耐压是否够。 4.计算初级线圈峰值电流 基于CCM模式计算的。ip1是开关管要关闭时的峰值电流,ip2是开关管开始导通时的起始电流。因为时CCM模式,所以,ip

ydgd118的博客 5万+

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

题目地址:POJ 2947 题意:N种物品,M条记录,接写来M行,每行有K,Start,End,表述从星期Start到星期End,做了K件物品,接下来的K个数为物品的编号。此题注意最后结果要调整到3-9之间。 思路: 很容易想到高斯消元。但是是带同余方程式的高斯消元,开始建立关系的时候就要MOD 7 解此类方程式时最后求解的过程要用到扩展gcd的思想,举个例子,如果最后得到的矩阵为:

Rocky0429 2825

【异常】Openclaw Gateway进程异常停止问题分析与解决方案

本文分析了Gateway服务异常停止的问题,提出了三种解决方案。核心问题是缺乏进程守护和自动恢复机制,导致服务崩溃后无法自行重启。推荐方案是使用PM2进程管理工具(方案1),提供进程监控、自动重启和开机自启功能。替代方案包括自定义守护脚本(方案2)和supervisord管理(方案3)。这些方案都能有效解决当前服务脆弱性问题,显著提升服务可用性,其中PM2方案成熟度高、配置简单,是首选解决方案。实施后可将服务从人工干预转变为自动恢复,确保业务连续性。

奶爸的编程之路,也就一周冷个三天 461

Python 爬虫实战:模拟登录网易云音乐(加密接口逆向与自动化登录实现)

网易云音乐作为国内主流的音乐流媒体平台,其丰富的音乐资源和个性化推荐算法吸引了大量用户。对于开发者而言,模拟登录网易云音乐并实现自动化操作,可以用于数据分析、歌单同步、歌词抓取等场景。然而,网易云音乐采用了多重加密机制和反爬策略,直接模拟登录存在较大挑战。

yansideyucsdn的博客 2590

poj 2947 Widget Factory(高斯消元 模线性方程)

题目链接:http://poj.org/problem?id=2947 大致题意:产品制造者制造型号不同的产品所需的时间是不同的(规定为3~9天),现在已知生产产品的的种数N和工作者的人数M,告诉你每个工作者是从星期几开始工作,星期几结束的(可能隔着n周),这个工作者生产了K件产品,产品的型号分别是多少。根据以上信息,求是否可以求出这N中产品的具体生产所需时间(无解 一解 多解),有解...

169

【XSRP软件无线电】基于软件无线电平台的QPSK频带通信系统设计(含有完整工程资料获取链接)

软件无线电(Software Defined Radio, SDR)是一种无线通信系统,它通过软件来定义和实现无线电的功能,而不是依赖于传统的硬件电路。SDR平台的核心思想是将传统无线电系统中的大部分硬件功能,如调制解调、信号处理、频率选择等,通过软件来实现。这种设计理念使得SDR具有高度的灵活性和可重配置性,能够适应不同的通信标准和频段,快速适应新的通信技术。

嵌入式技术开发 3286

poj 2947 Widget Factory(模7环上的高斯消元)

http://poj.org/problem?id=2947 大致题意: 有n种装饰物,m个已知条件,每个已知条件的描述如下: p start end a1,a2......ap (1 第一行表示从星期start到星期end一共生产了p件装饰物(工作的天数为end-start+1+7*x,加7*x是因为它可能生产很多周),第二行表示这p件装饰物的种类(可能出现相同的种类,即ai=aj)。

1151

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj 2947 Widget Factory (高斯消元,解模线性方程)

题意:生产一些零件,已知零件种数,记录条数 记录只记录了某次生产从周几开始,周几结束,以及生产了哪些产品。 每件商品生产所需天数为3-9天。 求每样产品需要多少天才能完成。 若无解输出Inconsistent data. 有无穷解输出Multiple solutions. 有唯一解,输出其解

happy_lcj 1799

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

poj 2947 Widget Factory 高斯消元解模线性方程

http://poj.org/problem?id=2947 思路: http://blog.youkuaiyun.com/u013486414/article/details/46999499 http://blog.youkuaiyun.com/sr_19930829/article/details/38275863 #include #include #include using namespace std

chen_minghui的博客 369

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

蓝书(算法竞赛进阶指南)刷题记录——POJ2947 Widget Factory(带模高斯消元)

题目:POJ2947. 题目大意:有nnn种部件,每种部件生产一个的时间为333~999天.现在给定mmm条记录,每个记录为某种kik_iki​个部件的生产时间为星期几sis_isi​到星期几tit_iti​,以及这kik_iki​个部件的类型,问每种部件单个生产所需的时间.若无解输出&amp;amp;amp;amp;quot;Inconsistent data.&amp;amp;amp;amp;quot;,有多组解输出&amp;amp;amp;amp;quot;Multiple s

hzk_cpp的博客 243

poj 2947 Widget Factory

Widget Factory 题意:有n件装饰品,有m组信息。(1 <= n ,m<= 300)每组信息有开始的星期和结束的星期(是在mod 7范围内的)并且还包括num种装饰品的种类(1~n),其中每种装饰品所用的时间3 <= x[i] <= 9;种类的输入可以重复; 思路: 1.根据输入建立增广矩阵a[][],但是在建立和求解的过程中由于是mod意义下的,所以输入...

weixin_30550271的博客 74

【POJ2947】 Widget Factory (模线性方程)

题目大意:n种零件,m次工作日程,零件序号从1到n,给出m次工作日程的信息,x,s,e,表示生产了x个零件,从星期s开始到星期e(有可能是多个星期),然后给出生产的x个零件的序号。求每个零件被生产需要多少天(保证在3到10天)解题思路:设未知数,列方程,高斯消元。

CaptainChen的博客 459

POJ - 2947 (Widget Factory)

题意:有 n 个零件,每个零件需要 [3,9] 内的其中一天完成,现给出 m 个工人开始开始和结束工作的日期(星期几) 还有它们加工的所有零件种类,求出每一种零件加工需要的时间; 分析:裸的高斯消元解同余线性方程组,套板子就行; 代码: #include<cmath> #include<cstdio> #include<cstring> #i...

Joker & Liar的博客 247

POJ2947 Widget Factory(高斯消元模板题)

传送门 大意:有n个变量,m个等式,求在 模7 意义下的解。 其实就是模板题,消完元之后如果有自由元就是有多个解,如果消完元之后有等式两边不等的情况,就是无解,否则有解。 代码:#include <cstdio> #include <cstring> #include <algorithm> #include <assert.h> using namespace std; #define MA

geng4512的专栏 700

poj2947——Widget Factory(高斯消元求模线性方程)

Widget Factory Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 5977   Accepted: 2082 Description The widget factory produces several different kinds of widge

我在浪里 375

POJ2947 Widget Factory【高斯消元】【同余方程】

题目大意: 有 N 种装饰物,M 个已知条件,每个已知条件描述为: p s t a1,a2,…,ap (1 <= ai <= N) 第一行表示从星期 s 到星期 t 一共生产了 p 件装饰物(工作天数可为 t - s + 1 + 7*x, 因为可能生产不只一周)。规定每件装饰物至少生产 3 天,最多生产 9天。问:每种装 饰物需要生产的天数。 如果没有解,则输出"Inconsistent data.",如果有多解,则输出"Multiple solutions." 如果有唯一解,则输出每种装饰

程序员充电站(itcharge) 711

【高斯消元 && 模线性方程 POJ 2947 Widget Factory】

Step1 Problem: 题意表述很好直接用了 给出零件的种类数量n与记录的条数m,紧接着有m条记录,记录了在星期几到星期几之间(有可能间隔多个星期)成产了多少个什么样的零件。求每个零件生产需要多少天。 输入: 2 3 2 MON THU 1 2 3 MON FRI 1 1 2 3 MON SUN 1 2 2 输出: 8...

ACMer 梁剑锋 的博客 276
上一篇: POJ 3185 The Water Bowls 【一维开关问题 高斯消元】
下一篇: HDU 1045 Fire Net 【连通块的压缩 二分图匹配】
莜莫oO
博客等级 码龄9年 7粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值