poj2947 高斯消元
Time Limit: 7000MS | Memory Limit: 65536K | |
Total Submissions: 5218 | Accepted: 1802 |
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
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
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
题意:
每个工人都有工作纪律,可以知道他做过哪些项目,总共用时多少
老板想知道每个项目要花费多少时间
思路:
因为你只知道开始和结束时间,并不知中经过了多少周,可以转化成方程组对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;
}
poj2947 高斯消元的更多相关文章
- poj2947(高斯消元解同模方程组)
题目链接:http://poj.org/problem?id=2947 题意:有n 种装饰物,m 个已知条件,每个已知条件的描述如下: p start enda1, a2......ap (1< ...
- 【poj2947】高斯消元求解同模方程组【没有AC,存代码】
题意: p start enda1,a2......ap (1<=ai<=n)第一行表示从星期start 到星期end 一共生产了p 件装饰物(工作的天数为end-start+1+7*x, ...
- 高斯消元 & 线性基【学习笔记】
高斯消元 & 线性基 本来说不写了,但还是写点吧 [update 2017-02-18]现在发现真的有好多需要思考的地方,网上很多代码感觉都是错误的,虽然题目通过了 [update 2017- ...
- 【BZOJ-3143】游走 高斯消元 + 概率期望
3143: [Hnoi2013]游走 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2264 Solved: 987[Submit][Status] ...
- 【BZOJ-3270】博物馆 高斯消元 + 概率期望
3270: 博物馆 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 292 Solved: 158[Submit][Status][Discuss] ...
- *POJ 1222 高斯消元
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 62 ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- hihoCoder 1196 高斯消元·二
Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...
- BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基
[题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...
随机推荐
- zookeeper 启动失败 BindException: Address already in use 或者Error contacting service. It is probably not running
平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6 hadoop 1.2.1 今天上午装storm的时候遇到这个问题,好郁闷.把网上介绍的方法 ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...
- Android类加载机制及热修复实现
Android类加载机制 Dalvik虚拟机如同其他Java虚拟机一样,在运行程序时首先需要将对应的类加载到内存中.而在Java标准的虚拟机中,类加载可以从class文件中读取,也可以是其他形式的二进 ...
- 配置Android开发环境遇到的问题
1.给Eclipse设置android的SDK位置时,出现这个:This Android SDK requires Andr...ate ADT to the latest 一个升级ADT到指定版本或 ...
- 爬虫必备 User-Agent 列表
USER_AGENTS = [ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR ...
- STM32-正弦波可调(50HZ~20KHZ可调、峰峰值0~3.3V可调)
1.原理: 通过定时器每隔一段时间触发一次DAC转换,然后通过DMA发送正玄波码表值给DAC. 当需要改变频率HZ时,只需要修改定时器频率即可(最高只能达到20KHz) 当需要改变正玄波的正峰峰值/负 ...
- SAP中的读访问日志Read Access Logging(RAL)
定义 读取访问日志(以下简称RAL)用于监视并记录对敏感数据的读取访问.这里的数据是指会被法律,外部公司政策或公司内部政策归类为敏感信息的数据.以下典型问题可能会与使用读取访问日志的应用程序有关: 谁 ...
- 学习React系列(七)——Fragments、Portals、Error Boundaries与WEB组件
React.Fragment portals Error Boundaries WEB组件 React.Fragment 想象一个场景,想把td包装为组件添加到table中去,代码如下: class ...
- 深入浅出理解 TCP/IP 协议 (一)
文章转自:https://www.cnblogs.com/onepixel/p/7092302.html TCP/IP 协议栈是一系列网络协议的总和,是构成网络通信的核心骨架,它定义了电子设备如何连入 ...
- [LeetCode] Valid Triangle Number 合法的三角形个数
Given an array consists of non-negative integers, your task is to count the number of triplets chose ...