THE MATRIX PROBLEM

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 41 Accepted Submission(s): 14
 
Problem Description
You have been given a matrix CN*M, each element E of CN*M is positive and no more than 1000, The problem is that if there exist N numbers a1, a2, … an and M numbers b1, b2, …, bm, which satisfies that each elements in row-i multiplied with ai and each elements in column-j divided by bj, after this operation every element in this matrix is between L and U, L indicates the lowerbound and U indicates the upperbound of these elements.
 
Input
There are several test cases. You should process to the end of file.
Each case includes two parts, in part 1, there are four integers in one line, N,M,L,U, indicating the matrix has N rows and M columns, L is the lowerbound and U is the upperbound (1<=N、M<=400,1<=L<=U<=10000). In part 2, there are N lines, each line includes M integers, and they are the elements of the matrix.

 
Output
If there is a solution print "YES", else print "NO".
 
Sample Input
3 3 1 6
2 3 4
8 2 6
5 2 9
 
Sample Output
YES
 
 
 
Source
2010 Asia Regional Harbin
 
Recommend
lcy
 
/*
题意:给你一个n*m的矩阵,现在问你,存不存在这样的两个序列,a1,a2...an, b1,b2....bm,使得矩阵每行的元素都乘a序列每
列的都除以b序列,这个操作之后,矩阵的每个元素都在[L,U]这个区间内。 初步思路:对每个元素与L,U联立不等式,然后按照不等式建边,再用spfa跑一下 #补充:虽然初步思路想的很好但是,还是想不出来怎么才能以i,j为参考进行建边,看了一下题解,L<=num[i][j]*a[i]/b[j]<=U
可以化简为,L/num[i]<=a[i]/b[i]<=U/num,但是现在中间的除法还是不好处理,经过log之后除法变成减法,就会处理了很多
log(L/num[i][j])<=log(a[i])-log(b[j])<=log(U/num[i][j]);
*/
#include<bits/stdc++.h>
using namespace std;
/*****************************************************spaf模板*****************************************************/
const int maxn = + ;
const int INF = 1e9 + ; typedef struct node{
int to;
int next;
double w;
node(int a = , int b = , double c = ){
to = a; next = b; w = c;
}
}Edge; int s[maxn * ];
double dis[maxn * ];
Edge edge[maxn * maxn * ];
int tot, head[maxn * maxn * ];
int vis[maxn * ], cnt[maxn * ]; void add(int u, int v, double w){
edge[tot] = node(v, head[u], w);
head[u] = tot++;
}
bool spfa(int e){
int u, v, top = ;
for(int i = ; i <= e; ++i){
dis[i] = INF;
vis[i] = ; cnt[i] = ;
}
s[top++] = ; vis[] = ; dis[] = ;
while(top){
u = s[--top]; vis[u] = ;
if((++cnt[u]) > e) return ;
for(int i = head[u]; ~i; i = edge[i].next){
v = edge[i].to;
if(dis[v] > dis[u] + edge[i].w){
dis[v] = dis[u] + edge[i].w;
if(!vis[v]){
s[top++] = v;
vis[v] = ;
}
}
}
}
return ;
}
/*****************************************************spaf模板*****************************************************/
void init(){
memset(head,-,sizeof head);
tot=;
}
int n,m,L,U;
int num;
int main(){
// freopen("in.txt","r",stdin);
while(~scanf("%d%d%d%d",&n,&m,&L,&U)){
init();
for(int i=;i<n;i++){
for(int j=;j<m;j++){
scanf("%d",&num);
//log(L/num[i][j])<=log(a[i])-log(b[j])
//i-j>=log(L/num[i][j])
add(i, j + n, log(1.0 * U / num));
//log(U/num[i][j])>=log(a[i])-log(b[j])
//i-j<=log(U/num[i][j]) add(j + n, i, -log(1.0 * L / num));
}
}
printf(spfa(n+m-)?"YES\n":"NO\n");
}
return ;
}

THE MATRIX PROBLEM的更多相关文章

  1. HDU 3666.THE MATRIX PROBLEM 差分约束系统

    THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. HDU 3666 THE MATRIX PROBLEM (差分约束 深搜 & 广搜)

    THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. hdoj--3666--THE MATRIX PROBLEM(差分约束+SPFA深搜)

    THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. HDU3666 THE MATRIX PROBLEM (差分约束+取对数去系数)(对退出情况存疑)

    You have been given a matrix C N*M, each element E of C N*M is positive and no more than 1000, The p ...

  5. HDU3666-THE MATRIX PROBLEM(差分约束-不等式解得存在性判断 对数转化)

    You have been given a matrix C N*M, each element E of C N*M is positive and no more than 1000, The p ...

  6. 差分约束系统+(矩阵)思维(H - THE MATRIX PROBLEM HDU - 3666 )

    题目链接:https://cn.vjudge.net/contest/276233#problem/H 题目大意:对于给定的矩阵  每一行除以ai  每一列除以bi 之后 数组的所有元素都还在那个L- ...

  7. HDU 3666 THE MATRIX PROBLEM (差分约束,最短路)

    题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存 ...

  8. HDU 3666 THE MATRIX PROBLEM (差分约束)

    题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l&l ...

  9. hduTHE MATRIX PROBLEM(差分约束)

    题目请戳这里 题目大意:给一个n*m的矩阵,求是否存在这样两个序列:a1,a2...an,b1,b2,...,bm,使得矩阵的第i行乘以ai,第j列除以bj后,矩阵的每一个数都在L和U之间. 题目分析 ...

随机推荐

  1. 使用JavaScript实现ATM取款机

    ATM机需求描述如下: 假设一个简单的ATM机的取款过程为:  首先提示用户输入密码(password),假设默认密码为111111,最多只能输入3次,  超过3次则提示用户"密码错误,请取 ...

  2. ngRepeat track by

    刚刚看见一篇文章讲述track by的功能的,大致记录如下: 1. ng-repeat="friend in friends" 一般不使用track by的情况下,每次刷新DOM, ...

  3. js 倒计时(服务器时间同步)

    首先说一下,为什么要服务器时间同步, 因为服务器时间和本地电脑时间存在一定的时间差.有些对时效性要求非常高的应用,例如时时彩开奖,是不能容忍这种时间差存在的. 方案1:每次倒计时去服务端请求时间 // ...

  4. ESC/POS打印控制命令

    0x00. Command Notation [Name]                        The name of the command. [Format]               ...

  5. LCM Cardinality 暴力

    LCM Cardinality Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  6. 【笔记】Kali linux的安装 和 一些使用前的准备工作(原创+转载)

    该博文只记录笔者的蛇皮使用经历,纯新手= =,可能借鉴意义也可能没有(T _ T),侵删. 目录 kali linux 在个人计算机和在VirtualBox下的安装 kali linux 使用前准备工 ...

  7. Linux下将Apache(httpd)新增为系统服务及开机自启动

    1. 查看一下/etc/init.d/下是否存在httpd这个服务 ls /etc/init.d/ | grep httpd 如果没有执行下一步 2.将自己安装目录下的apachect1复制到该目录下 ...

  8. Python自学笔记-关于切片(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 切片 L[0: ...

  9. Another app is currently holding the yum lock; waiting for it to exit 解决方法

    Another app is currently holding the yum lock; waiting for it to exit... The other application is: P ...

  10. ActiveMQ——activemq的详细说明,queue、topic的区别(精选)

    JMS中定义了两种消息模型:点对点(point to point, queue)和发布/订阅(publish/subscribe,topic).主要区别就是是否能重复消费. 点对点:Queue,不可重 ...