poj2947 高斯消元

POJ 2947 高斯消元--判断一解多解无解 又是偷来的代码,但是第一道高斯消元,纪念下 知道每条式子的结果取模后的值,求方程组,这不同于一般的高斯消元,而且答案必须为整数并在一定区间内 1.由于是整数要用到gcd; 2.解的判断: 有解的情况都是必须满足row一下全为0 一解:化简后是严格的三角矩阵 多解:自由变量个数较少 无解:row以下有非0的 #include #include #include #inclu 阅读详情

Widget Factory
Time Limit: 7000MS Memory Limit: 65536K
Total Submissions: 5218 Accepted: 1802

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. 

题意:

每个工人都有工作纪律,可以知道他做过哪些项目,总共用时多少

老板想知道每个项目要花费多少时间

思路:

因为你只知道开始和结束时间,并不知中经过了多少周,可以转化成方程组对mod取模套用即可,在得出x处,如果答案小于3,则要进行修改,要求的是在3—9天,WR了很久,最后发现是因为周二单词的缩写弄错了TAT



#include <functional>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <Map>
using namespace std;
typedef long long ll;
typedef long double ld;

using namespace std;
const int maxn = 305;
int equ,var;
int a[maxn][maxn];
int x[maxn];
int free_x[maxn];
int free_num;

void debug()
{
    for(int i = 0; i < equ; i++)
    {
        for(int j = 0; j <= var; j++)
            printf("%d ",a[i][j]);
        printf("\n");
    }
}

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

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

int Gauss(int mod)
{
    int max_r,col,k;
    free_num = 0;
    for(k = 0,col = 0; k < equ && col < var; k++,col++)
    {
        max_r = k;
        for(int i = k+1; i < equ; i++)
        {
            if(abs(a[i][col]) > abs(a[max_r][col]))
                max_r = i;
        }
        if(a[max_r][col] == 0)
        {
            k --;
            free_x[free_num++] = col ;
            continue;
        }
        if(max_r != k)
        {
            for(int j = col; j < var+1; j++)
                swap(a[k][j],a[max_r][j]);

        }
        for(int i = k + 1; i < equ; i++)
        {
            if(a[i][col] != 0)
            {
                int LCM = lcm(abs(a[i][col]),abs(a[k][col]));
                int ta = LCM / abs(a[i][col]);
                int tb = LCM / abs(a[k][col]);
                if(a[i][col] * a[k][col] < 0) tb = -tb;
                for(int j = col; j < var+1; j++)
                {
                    a[i][j] = ((a[i][j]*ta - a[k][j]*tb)%mod+mod)%mod;
                }
            }
        }

    }
    for(int i = k; i < equ; i++)
        if(a[i][col] != 0)
            return -1;
    if(k < var) return var-k;

    for(int i = var-1; i >= 0; i--)
    {
        ll temp = a[i][var];
        for(int j = i +1; j < var; j++)
            temp =((temp- a[i][j]*x[j])%mod+mod)%mod;
        while(temp % a[i][i])
        {
            temp += mod;
        }
        temp /= a[i][i];
        temp %= 7;
        if(temp < 3)
            temp += 7;
        x[i] = temp;
    }
    return 0;
}

int n,m;
void ini()
{
    memset(a,0,sizeof(a));
    memset(x,0,sizeof(x));
    equ = m;
    var = n;
}

map<string,int>mp;

void get()
{
    mp["MON"] = 1;
    mp["TUE"] = 2;
    mp["WED"] = 3;
    mp["THU"] = 4;
    mp["FRI"] = 5;
    mp["SAT"] = 6;
    mp["SUN"] = 7;
}
string star;
string en;

int main()
{
    int k;
    get();
    while(scanf("%d%d",&n,&m) != EOF)
    {
        if(!n && !m)
            break;
        ini();

        for(int i = 0; i < m; i++)
        {
            cin>>k>>star>>en;

            int day = mp[en] - mp[star]+1;
            if(day < 0)
                day += 7;
            a[i][n] =day;
            for(int j = 0; j < k; j++)
            {
                int x;
                scanf("%d",&x);
                a[i][x-1] ++;
            }
             for(int j = 0; j < n; j++)
            {
                a[i][j] %= 7;
            }
        }
        //debug();
        int ans = Gauss(7);

        if(ans == -1)
        {
            printf("Inconsistent data.\n");
        }
        else if(ans > 0)
            printf("Multiple solutions.\n");
        else
        {
            for(int i = 0; i < var; i ++ )
            {
                 printf("%d%c", x[i], i == var-1 ? '\n' : ' ');
            }
        }
    }
    return 0;
}





从MRF8P9040N数据手册到ADS仿真:手把手教你搞定LDMOS功放设计(附完整模型下载) 本文详细解析了MRF8P9040N LDMOS功率放大器的数据手册关键参数,并提供了在ADS中进行仿真的完整指南。从模型导入、直流工作点验证到负载牵引与阻抗匹配设计,逐步指导工程师完成高效功放设计。文章还包含调试技巧和常见问题解决方案,帮助优化射频功放性能。 阅读详情

相关推荐

WGS-84 ECEF ENU 坐标系学习记录

地球坐标系固定在地球上而随地球一起在空间做公转和自转运动,因此地球上任一固定点在地球坐标系的坐标就不会由于地球旋转而变化。地心地固直角坐标系和大地坐标系都属于这种坐标系。 一、 几种坐标系 地心地固直角坐标系(ECEF)坐标系 其原点为地球的质心,x轴延伸通过本初子午线(0度经度)和赤道(0deglatitude)的交点。 z轴延伸通过的北极(即,与地球旋转轴重合)。 y轴完成右手坐标系,穿...

YYshuangshuang的博客 1万+

pku 1952 BUY LOW, BUY LOWER(DP)

BUY LOW, BUY LOWER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7483   Accepted: 2609 Description The advice to "buy low" is half the formula to success

街角的花街糖 1165

超越数据手册:深入Zynq XADC的DRP接口与PL端自定义采样逻辑

本文深入探讨Zynq-7000系列XADC模块的DRP接口机制与PL端自定义采样逻辑实现。通过硬件级多通道轮询、触发采样和实时校准技术,突破传统软件驱动限制,为高精度电压测量和通讯应用提供极致灵活性和响应速度。

xxx12的博客 770

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

Qt 插件开发 plugin 超详细 有源码

Qt 插件化开发框架类似于前后端的微服务的场景,授权哪个微服务则前端可以使用哪个微服务,插件就行硬件插卡一样,可以被随时删除、插入和修改,所以结构很灵活,容易修改,方便软件的升级和维护;插件主要面向接口编程,无需访问.lib文件,热插拔、利于团队开发。即使在程序运行时.dll不存在,也可以正常启动,只是相应插件功能无法正常使用而已;动态库需要访问.lib文件,而且在程序运行时必须保证.lib存在,否则无法正常启动;

q610098308的专栏 6546

数据仓库从明细到汇总:DWD与DWS层建模实战指南

DWS层的“主题”是指业务分析的核心场景,通常分为“用户主题、商品主题、订单主题、营销主题”等。主题的定义需紧密结合业务需求,避免“为了汇总而汇总”。例如,电商平台的核心业务需求包括“用户活跃度分析”“商品销售情况分析”“订单转化分析”,对应的DWS层主题即可定义为“用户主题汇总表”“商品主题汇总表”“订单主题汇总表”。主题定义时需注意“粒度适中”——汇总粒度既不能过细(否则与DWD层重复,失去汇总意义),也不能过粗(否则无法满足细分分析需求)。

2401_83088008的博客 644

高斯消元解同余方程组

SETI 题意:输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'*'对应0,‘a’对应1,‘b’对应2···   eg:str[] = "abc", 那么说明 n=3, 字符串所对应的数列为1, 2, 3。 题目定义了一个函数:a0*1^0 + a1*1^1+a2*1^2+........+an-1*1^(n-1) = f(1)(mod p), f(1

周周的博客 673

【大语言模型 37】知识蒸馏深度实战:大模型向小模型迁移

本文深入探讨了知识蒸馏技术在大语言模型领域的应用,详细阐述了如何将庞大复杂的大模型知识有效迁移到轻量级小模型中。文章系统介绍了知识蒸馏的理论基础、多种蒸馏损失函数设计、特征匹配与注意力迁移技术、渐进式蒸馏策略以及全面的效果评估方法。通过实战案例和完整代码实现,读者将掌握从理论到实践的知识蒸馏全流程,了解如何在保持模型性能的同时显著降低计算资源需求,实现大语言模型的高效部署与应用。

熵数实验室 1508

POJ 2065 SETI(高斯消元解同余方程组)

传送门SETITime Limit: 1000MSMemory Limit: 30000KTotal Submissions: 1882Accepted: 1165DescriptionFor some years, quite a lot of work has been put into listening to electromagnetic radio signals received fr

代码改变世界 1299

Isaac Sim 入门教程(四)强化学习策略训练宇树人形机器人四足机器人示例

isaac_sim_policy_example Extension 是在 Isaac Sim 中部署 Isaac Lab 强化学习策略的一个框架和一组辅助函数。有关在 Isaac Sim 中训练和构建策略的详细信息,请访问在 Isaac Sim 中部署策略。该扩展程序默认已启用。如果被禁用,可在扩展管理器中搜索 isaacsim.robot.policy.example 重新启用。要运行下面的示例,请激活 “视窗”>“示例”>“机器人示例”,这将打开 “机器人示例 ”选项卡。

机器人控制与仿真应用 3925

SAP Build Work Zone standard edition 订阅报错 OIDC trust missing 的成因与完整解决路径

摘要:用户订阅SAP Build Work Zone时遇到422错误,提示未配置OpenID Connect信任。该错误表明业务用户需通过SAP Cloud Identity Services的OIDC协议认证,而当前子账户仅配置了SAML信任或未配置信任。解决方法是进入子账户的Trust Configuration页面,使用Establish Trust功能建立与SAP Cloud Identity Services的OIDC信任关系。这是SAP新版服务的强制要求,SAML协议已不被支持。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 197

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

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

weixin_30810239的博客 261

特别章节-0.1 SolidWorks导出机械臂的URDF模型各个关节坐标系设置

通过Solidworks导出机械臂的URDF模型文件,建立机械臂的各个关节坐标系的规则以及注意点,详细步骤

六眼飞鱼的博客 1万+

POJ 2947 线性同余方程组 + 高斯消元

题解 传送门 POJ 2947 Widget Factory 题解 设制作第 iii 类装置需要的时间为 xix_ixi​,对于每条记录,统计在工人工作时间内各类装置制作的数量 aia_iai​,设开始、结束的星期数之差为 bib_ibi​,由于不知道工人开始、结束工作相隔多少周,于是得到一个模数为 777 的线性同余方程 ∑i=0n−1aixi=bimod  7\sum\limits_{i=0}^{n-1}a_ix_i=b_i\mod 7i=0∑n−1​ai​xi​=bi​mod7 共 mmm 条记录,故

neweryyy的博客 302

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 2947 Widget Factory 高斯消元

转载请注明出处,谢谢 http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents           by---cxlove 继续高斯消元 建立方程 A11*X1+A12*X2+……A1N*XN同余B1%7 A21*X1+A22*X2+……A2N*XN同余B2%7 AM1*X1+AM2*X2+……AMN*XN同余BM%7 然后便是

窝不是爱酱,喵~~~~ 2414

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

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

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

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

happy_lcj 1799

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

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

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

Rocky0429 2824

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

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

169

poj 2947 Widget Factory (高斯消元解同余方程组+判断无解、多解)

http://poj.org/problem?id=2947 血泪史: CE:poj的string类型要加string库,swap不能直接交换数组 WA: x[m-1]也有可能<3啊O(≧口≦)O #include<cstdio> #include<cstring> #include<iostream> #i...

weixin_34402408的博客 165

poj 2947 高斯消元求解方程组取模

题意: (mat[1][1]*x[1] + mat[1][2]*x[2] + … + mat[1][n]*x[n])%7 =mat[1][n+1] (mat[2][1]*x[1] + mat[2][2]*x[2] + … + mat[2][n]*x[n])%7 =mat[2][n+1] … … (mat[m][1]*x[1] + mat[m][2]*x[2] +

渐近自由 723

POJ2947 Widget Factory [高斯消元]

Widget  Factory\mathcal{Widget\ \ Factory}Widget  Factory

Zbr162的博客 161

POJ 2947 2947 Widget Factory 高斯消元

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

weixin_34186931的博客 111

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

[poj2947][高斯消元]Widget Factory

传送门: http://poj.org/problem?id=2947 这个代码是错的,我也不是很清楚为啥错了,高消的部分被我拿去交seti那题过了。。可能系数求错了?如果有人看我这个博文发现出了偏差请帮忙指正一下谢谢了。 sol: 题目就是给出了一系列同余方程组,解方程即可。 #include&lt;iostream&gt; #include&lt;algorithm&gt; #inc...

Gzb1128的栖息地 258

【POJ 2947】Widget Factory(高斯消元+逆元)

【POJ 2947】Widget Factory(高斯消元+逆元) Widget Factory Time Limit: 7000MSMemory Limit: 65536KTotal Submissions: 5464Accepted: 1884DescriptionThe widget factory produces several different kinds of widgets. Ea

ACMer' 1160

poj2947 Widget Factory 【高斯消元】

链接:http://poj.org/problem?id=2947 题意:有n个部件,m个记录,记录描述了,某些部件在那个时间段(只说明了星期a到星期b,没有明确多少时间),每个部件完成的 时间3~9天。现在要你找出每个部件完成的时间。 思路:每个记录的时间可以表示为 ((b-a+1)%7+7)%7.  很显然,每个记录都可以看成一个方程,所以就有m个方程,n个未知数,用高斯消元求解 代码

Fb_by 265
上一篇: poj 2065 高斯消元(取模的方程组)
下一篇: hdu 2665 划分树
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值