THE MATRIX PROBLEM
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 |
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的更多相关文章
- HDU 3666.THE MATRIX PROBLEM 差分约束系统
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 3666 THE MATRIX PROBLEM (差分约束 深搜 & 广搜)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdoj--3666--THE MATRIX PROBLEM(差分约束+SPFA深搜)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 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 ...
- 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 ...
- 差分约束系统+(矩阵)思维(H - THE MATRIX PROBLEM HDU - 3666 )
题目链接:https://cn.vjudge.net/contest/276233#problem/H 题目大意:对于给定的矩阵 每一行除以ai 每一列除以bi 之后 数组的所有元素都还在那个L- ...
- HDU 3666 THE MATRIX PROBLEM (差分约束,最短路)
题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存 ...
- HDU 3666 THE MATRIX PROBLEM (差分约束)
题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l&l ...
- hduTHE MATRIX PROBLEM(差分约束)
题目请戳这里 题目大意:给一个n*m的矩阵,求是否存在这样两个序列:a1,a2...an,b1,b2,...,bm,使得矩阵的第i行乘以ai,第j列除以bj后,矩阵的每一个数都在L和U之间. 题目分析 ...
随机推荐
- SQL 常用语法一
整理笔记,并将常用的SQL语法记录下来. 这些方法有 CASE WHEN, IFNULL,GROUP BY,LIMIT,SUBSTR 1,字段转换 CASE WHEN 意义: If(a==b) a=c ...
- java实现excel和数据的交互
1. 环境要求 本文环境为: 数据库为oracle,jdk为jdk7,依赖jar包为ojdbc6-11.2.0.4.0.jar+poi-3.14.jar 2.POI 使用 1. 建立工作空间 2. 获 ...
- 西邮linux兴趣小组2014纳新免试题(一)
[第一关] 题目 0101001001100001011100100010000100011010000001110000000011001111100100000111001100000000000 ...
- SpringAop详解
近几天学习了一下SpringAop在网上找了一些资料,此链接为原文链接http://www.cnblogs.com/xrq730/p/4919025.html AOP AOP(Aspect Orien ...
- ptyhon 编程基础之函数篇(二)-----返回函数,自定义排序函数,闭包,匿名函数
一.自定义排序函数 在Python中可以使用内置函数sorted(list)进行排序: 结果如下图所示: 但sorted也是一个高阶函数,可以接受两个参数来实现自定义排序函数,第一个参数为要排序的集合 ...
- PLT文件 和 DXF文件
PLT: CAM/CAD类似软件处理的图像文件的文件格式 DXF: AutoCAD(Drawing Interchange Format或者Drawing Exchange Format) 绘图交换文 ...
- ObjectSNMP
下面的例子,就是使用ObjectSNMP获取RFC1213-MIB的例子:其中的system和ifTable对象就是对应的SNMPMIB中的system组合interface中的ifTable表. p ...
- 代理模式与java中的动态代理
前言 代理模式又分为静态代理与动态代理,其中动态代理是Java各大框架中运用的最为广泛的一种模式之一,下面就用简单的例子来说明静态代理与动态代理. 场景 李雷是一个唱片公司的大老板,很忙, ...
- python爬取煎蛋网图片
``` py2版本: #-*- coding:utf-8 -*-#from __future__ import unicode_literimport urllib,urllib2,timeimpor ...
- Pycharm安装、设置、优化
一.版本选择 建议安装5.0版本,因为好注册,这个你懂得. 下载地址: https://confluence.jetbrains.com/display/PYH/Previous+PyCharm+Re ...