HDU 3666.THE MATRIX PROBLEM 差分约束系统
THE MATRIX PROBLEM
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8693 Accepted Submission(s): 2246
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.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define bug(x) cout<<"bug"<<x<<endl;
#define PI acos(-1.0)
#define eps 1e-8
typedef long long ll;
typedef pair<int,int> P;
const int N=,M=1e6;
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
const double INF=;
struct edge
{
int from,to;
double w;
int next;
};
int n,m;
edge es[M];
int cut,head[N];
double dist[N];
void init()
{
cut=;
memset(head,-,sizeof(head));
}
void addedge(int u,int v,double w)
{
///cout<<u<<" ** "<<v<<" ** "<<w<<endl;
cut++;
es[cut].from=u,es[cut].to=v;
es[cut].w=w;
es[cut].next=head[u];
head[u]=cut;
}
bool spfa()
{
int cou=;
queue<int>q;
bool inq[N];
for(int i=; i<=n+m+; i++) dist[i]=inf,inq[i]=false;
dist[]=;
q.push();
while(!q.empty())
{
int u=q.front();
q.pop();
inq[u]=false;
if(++cou>*(n+m)) return false;
for(int i=head[u]; i!=-; i=es[i].next)
{
edge e=es[i];
if(dist[e.to]>dist[e.from]+e.w)
{
dist[e.to]=dist[e.from]+e.w;
///cout<<e.from<<" * "<<e.to<<" * "<<dist[e.to]<<endl;
if(!inq[e.to]) q.push(e.to),inq[e.to]=true;
}
}
}
return true;
}
int main()
{
double l,u;
while(scanf("%d%d%lf%lf",&n,&m,&l,&u)!=EOF)
{
init();
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
double g;
scanf("%lf",&g);
addedge(i,n+j,log2(g)-log2(l));
addedge(n+j,i,log2(u)-log2(g));
}
}
if(spfa()) puts("YES");
else puts("NO");
}
return ;
}
差分约束
HDU 3666.THE MATRIX PROBLEM 差分约束系统的更多相关文章
- HDU 3666 THE MATRIX PROBLEM (差分约束)
题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l&l ...
- 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 (差分约束,最短路)
题意: 给一个n*m矩阵,每个格子上有一个数字a[i][j],给定L和U,问:是否有这样两个序列{a1...an}和{b1...bn},满足 L<=a[i][j]*ai/bj<=U .若存 ...
- hdu 3666 THE MATRIX PROBLEM
差分约束系统. 根据题意,可以写出不等式 L <= (Xij * Ai) / Bj <= U 即 Ai/Bj<=U/Xij和Ai/Bj>=L/Xij 由于差分约束系统是减法.. ...
- 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 ...
- hduTHE MATRIX PROBLEM(差分约束)
题目请戳这里 题目大意:给一个n*m的矩阵,求是否存在这样两个序列:a1,a2...an,b1,b2,...,bm,使得矩阵的第i行乘以ai,第j列除以bj后,矩阵的每一个数都在L和U之间. 题目分析 ...
- ZOJ 1455 Schedule Problem(差分约束系统)
// 题目描述:一个项目被分成几个部分,每部分必须在连续的天数完成.也就是说,如果某部分需要3天才能完成,则必须花费连续的3天来完成它.对项目的这些部分工作中,有4种类型的约束:FAS, FAF, S ...
- 差分约束 HDU - 1384 HDU - 3592 HDU - 1531 HDU - 3666
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- Centos7创建CA和申请证书 转自https://www.cnblogs.com/mingzhang/p/8949541.html
Centos7.3创建CA和申请证书 openssl 的配置文件:/etc/pki/tls/openssl.cnf 重要参数配置路径 dir = /etc/pki/CA ...
- 1131(★、※)Subway Map
思路:DFS遍历 #include <iostream> #include <map> #include <vector> #include <cstdio& ...
- Android 最简单的MVP案例;
随手撸个发出来: V:界面层 //界面层需要实现P.View方法,然后重写P.View中的方法:M层给的数据就在这些个方法的参数中: // 还要获取到P.Provide的实例,使用P.Provide去 ...
- 团队第三次 # scrum meeting
github 本此会议项目由PM召开,召开时间为4-7日晚上9点 召开时长15分钟 任务表格 袁勤 继续学习SpringBoot https://github.com/buaa-2016/phyweb ...
- 模拟实现简单ATM功能
- html 设置input框的记忆功能(联想内容)
autocomplete=“on/off” 1.默认情况下,autocomplete的值是on.你可以将其设置为off. 2.autocomplete属性可以放在input 元素上,也可以放在form ...
- c# ref与out用法
class Program { static void Main(string[] args) { //普通 : ; ); Console.WriteLine("/*普通:*/") ...
- Java 身份证判断性别获取年龄
import com.alibaba.fastjson.JSON; import org.junit.Test; import java.text.SimpleDateFormat; import j ...
- spring boot报Unsupported Media Type Content type '*/*;charset=UTF-8' not supported
1.请求设置Content-Type:application/json即可 ajax一般默认:Content-Type: application/x-www-form-urlencoded;chars ...
- jsp页面中比较“接收数据”与“页面循环数据”是否相等
页面中关系运算符: -lt 小于 -le 小于或者等于 -gt 大于 -ge 大于或者等于 -eq 等于 -ne 不等于 判空:<c:if test="${empty count ...