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 ...
随机推荐
- Basys3在线调试视频指南及代码
fpga在线调试视频链接 FPGA选择型号:xc7a35tcpg236-1 des文件 `timescale 1ns / 1ps module top( output [1:0] led, outpu ...
- Django Haystack 全文检索与关键词高亮
Django Haystack 简介 django-haystack 是一个专门提供搜索功能的 django 第三方应用,它支持 Solr.Elasticsearch.Whoosh.Xapian 等多 ...
- JAVA中最容易让人忽视的基础。
可能很多找编程工作的人在面试的时候都有这种感受,去到一个公司填写面试试题的时候,多数人往往死在比较基础的知识点上.不要奇怪,事实就是如此一般来说,大多数公司给出的基础题大概有122道,代码题19道左右 ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- 通过URL传递PDF名称参数显示PDF
1 <%@ page language="java" import="java.util.*,java.io.*" 2 pageEncoding=&quo ...
- LeetCode & Q219-Contains Duplicate II
Array Hash Table Description: Given an array of integers and an integer k, find out whether there ar ...
- httpClient解决post请求重定向的问题
import com.dadi.saas.util.HTTPUtils; import org.apache.commons.httpclient.Header; import org.apache. ...
- cookie中存中文
cookie中存中文 1:想要在cookie中存中文:需要用到URLEncoder(在jdkAPI中有介绍) Cookie cookie = new Cookie("User",U ...
- Docker学习笔记 - Docker的镜像
一个容器实际上是运行在宿主机上的一个进程. 只不过在启动这个进程之前进行了一些特殊处理,让这个容器进入了一个全新的虚拟环境,与宿主机的环境分开, 所以这个进程及其子进程认为自己运行在一个独立的世界里面 ...
- codeforces 798c Mike And Gcd Problem
题意: 给出一个数列,现在有一种操作,可以任何一个a[i],用a[i] – a[i+1]和a[i]+a[i+1]替代a[i]和a[i+1]. 问现在需要最少多少次操作,使得整个数列的gcd大于1. 思 ...