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 ...
随机推荐
- docker-compose 安装redis sentinel,共享主机网络模式
采坑记录: docker sentinel模式安装完后因为是使用bridge模式,所以只有docker中运行的程序才能访问.刚开始尝试使用端口映射,返现sentinel返回的地址依然是docker的内 ...
- Python——列表、元祖、字典、集合的基本操作
列表 1. 列表——增 (1)append li = ['xcsd', 'cdc', [1, 5, 2], 'eht', '辛辰'] li.append('nihao') print(li) #['x ...
- Oauth2.0客户端服务端示例
https://blog.csdn.net/qq_28165595/article/details/80459185 前言前面的理解OAuth2.0认证与客户端授权码模式详解,我们大致了解了Oauth ...
- MOBA英雄AI设计分享
转自:http://www.gamelook.com.cn/2018/07/333877 文/wataloo 1 设计概要 1.1 设计原则和目的 英雄AI的目的主要有: 1.新手过渡局,让玩家刚 ...
- ef join查询
temp = temp.OrderByDescending(s => s.CreateTime).Skip((param.PageIndex - ) * param.PageSize).Take ...
- mysql相关碎碎念
取得当天: SELECT curdate(); mysql> SELECT curdate();+------------+| curdate() |+------------+| 2013- ...
- android 开发 View _15 导入一张图片将它裁剪成圆形 与 paint图层叠加处理详解
方法一: /* 实现思维是这样的: 1.首先拿到bitmap图片 2.得到bitmap图片的高度 宽度,并且计算好各个画图尺寸 3.创建一个空白的 bitmap图片: Bitmap output = ...
- 面试回顾——kafka
关于消息队列的使用场景:https://www.cnblogs.com/linjiqin/p/5720865.html kafka: Topic Kafka将消息种子(Feed)分门别类 每一类的消息 ...
- 配置yum源
本文转载:https://www.cnblogs.com/yangp/p/8506264.html (一)yum源概述 yum需要一个yum库,也就是yum源.默认情况下,CentOS就有一个yum源 ...
- 【转】完整精确导入Kernel与Uboot参与编译了的代码到Source Insight,Understand, SlickEdit
The linux kernel and u-boot contains lots of files, when we want to broswe the source code,we just w ...