THE MATRIX PROBLEM_差分约束_2018_3_18
2018-03-18 09:55
274 查看
这种写法就是判断负环
L<=num[i][j]*b[j]/a[i]<=U
#define c num[i][j]
L/c<=b[j]/a[i]<=U/c
log(L/c)<=log(b[j])-log(a[i])<=log(U/c)
L<=num[i][j]*b[j]/a[i]<=U
#define c num[i][j]
L/c<=b[j]/a[i]<=U/c
log(L/c)<=log(b[j])-log(a[i])<=log(U/c)
THE MATRIX PROBLEMTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8900 Accepted Submission(s): 2290 [align=left]Problem Description[/align] 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. [align=left]Input[/align] 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. [align=left]Output[/align] If there is a solution print "YES", else print "NO". [align=left]Sample Input[/align]3 3 1 62 3 48 2 65 2 9 [align=left]Sample Output[/align]YES [align=left]Source[/align] 2010 Asia Regional Harbin [align=left]Recommend[/align] lcy | We have carefully selected several similar problems for you: 3665 3669 3667 3664 3663 Statistic | Submit | Discuss | Note |
#include<iostream> #include<cmath> #include<cstring> using namespace std; int n,m; double l,u; int num; #define f(i,n) for(i=1;i<=n;i++) const int N=1e4; int vis ,head ; double dis ; struct AA{ int v,next; double w; }edge[N*N]; void add(int u,int v,double w){ edge[num].v=v; edge[num].next=head[u]; edge[num].w=w; head[u]=num++; } int spfa(int u){ vis[u]=1; for(int h=head[u];h;h=edge[h].next){ int v=edge[h].v; if(dis[v]>dis[u]+edge[h].w){ dis[v]=dis[u]+edge[h].w; if(vis[v])return v; int ret=spfa(v); if(ret!=-1)return ret; } } vis[u]=0; return -1; } int solve(){ memset(vis,0,sizeof(vis)); memset(dis,0,sizeof(dis)); int i; f(i,n+m){ int ret=spfa(i); if(ret!=-1)return ret; } return -1; } int main(){ while(~scanf("%d%d%lf%lf",&n,&m,&l,&u)){ num=0; memset(head,0,sizeof(head)); int i,j; f(i,n)f(j,m){ double a; scanf("%lf",&a); add(j+n,i,log(u/a)); add(i,j+n,log(a/l)); } if(solve()==-1)puts("YES"); else puts("NO"); } }
相关文章推荐
- hdu 3666 THE MATRIX PROBLEM (差分约束 + 最长路)
- hdu 3666 THE MATRIX PROBLEM(差分约束,思路)
- hdu 3666 THE MATRIX PROBLEM (差分约束)
- hduTHE MATRIX PROBLEM(差分约束)
- UVALive 5094 - THE MATRIX PROBLEM(差分约束)
- HDU 3666 THE MATRIX PROBLEM (差分约束判负环)
- HDU 3666 THE MATRIX PROBLEM (差分约束,最短路)
- hdu 3666 THE MATRIX PROBLEM (差分约束)
- HDU 3666&& UVALive - 5094 THE MATRIX PROBLEM(stack判负环,差分约束)
- HDU 3666 THE MATRIX PROBLEM (差分约束判负环)
- HDU 3666 THE MATRIX PROBLEM 解题报告(差分约束)
- hduTHE MATRIX PROBLEM(差分约束)
- HDU 3666 THE MATRIX PROBLEM(差分约束 + spfa 深搜判环)
- HDU 3666 THE MATRIX PROBLEM(差分约束)
- hdu3666 THE MATRIX PROBLEM(差分约束||乘除变加减)
- HDOJ 3666 THE MATRIX PROBLEM 差分约束
- HDU3666-THE MATRIX PROBLEM(差分约束-不等式解得存在性判断 对数转化)
- hdu 3666 THE MATRIX PROBLEM (差分约束)
- hdoj 3666 THE MATRIX PROBLEM 【差分约束】
- Hdu 3666 THE MATRIX PROBLEM(差分约束)