Probelm
You have been given a matrix C N*M, each element E of C N*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”
题意描述
给出一个 N∗MN∗M 的矩阵 CC,要求构造两个序列 和 b1,b2,...,bmb1,b2,...,bm
矩阵的第 ii 行元素乘上,矩阵的第 jj 列元素除以 ,最终矩阵的每个元素Cij∈[L,U]Cij∈[L,U]
若可以构造成功,则输出”YES”,否则输出”NO”
题解
依题意
对上列式子两边取loglog,得
将序列 a,ba,b 整合为一个序列记为 SS
为原 aa 序列取,Sn+1...Sn+mSn+1...Sn+m 为原 bb 序列取
则上式为
故有线性约束条件如下
约束图表示为 w(i,n+j)=logCijLw(i,n+j)=logCijL 及 w(n+j,i)=logUCijw(n+j,i)=logUCij
代码
#include<bits/stdc++.h>
using namespace std;
const double inf = 1e9;
const int maxn = 550;
struct node
{
int to;
double w;
node (int i=0,double j=0)
{
to = i, w = j;
}
};
int n,m,l,u,uptimes,cnt[maxn<<1];
double d[maxn<<1];
bool vis[maxn<<1];
vector <node> g[maxn<<1];
bool spfa()
{
queue <int> q;
q.push(0);
vis[0] = 1;
d[0] = 0;
while (!q.empty())
{
int u = q.front();
for (int i=0;i<g[u].size();i++)
{
int v = g[u][i].to;
double dis = g[u][i].w;
if (d[v] > d[u]+dis)
{
d[v] = d[u]+dis;
if (!vis[v])
{
vis[v] = 1;
q.push(v);
if (++cnt[v] > uptimes) return false;
}
}
}
q.pop();
vis[u] = 0;
}
return true;
}
int main()
{
while (scanf("%d %d %d %d",&n,&m,&l,&u)!=EOF)
{
uptimes = sqrt(n+m);
for (int i=0;i<n+m;i++)
{
g[i].clear();
vis[i] = cnt[i] = 0;
d[i] = inf;
}
int x;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
{
scanf("%d",&x);
g[j+n].push_back(node(i,log((double)u/x)));
g[i].push_back(node(j+n,log((double)x/l)));
}
if (spfa()) printf("YES\n");
else
printf("NO\n");
}
return 0;
}

该博客介绍了HDU 3666编程问题,要求找到一组数值a和b,使得经过特定操作后矩阵的每个元素位于[L, U]区间。题目提供了输入输出格式和题意解析,并提出了解题思路。"
2913846,378107,VB.NET实现网络麻将游戏开发,"['游戏开发', 'VB.NET编程', '网络编程', '数据库设计', '游戏规则实现']
&spm=1001.2101.3001.5002&articleId=81296547&d=1&t=3&u=263d2d4ace8e4ce8a2ce731e20f614e1)
283

被折叠的 条评论
为什么被折叠?



