bzoj 4819: [Sdoi2017]新生舞会
Description
Input
Output
Sample Input
19 17 16
25 24 23
35 36 31
9 5 6
3 4 2
7 8 9
Sample Output
HINT
Source
// MADE BY QT666
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include<vector>
#define RG register
#define int long long
using namespace std;
typedef long long ll;
const int N=100000;
const double eps=1e-9;
const double Inf=19260817.0;
int gi() {
int x=0,flag=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') flag=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*flag;
}
int n,ans,flag1,flag2;
int head[N],nxt[N],to[N],s[N],cnt=1,S,T;
double cc[N],dis[N],cost;
int a[300][300],b[300][300];
int level[N],q[N*10],F,fa[N],W[N];
struct data {
int l,r,s,t;
} hh[N];
inline void Addedge(RG int x,RG int y,RG int z,RG double u) {
to[++cnt]=y,s[cnt]=z,cc[cnt]=u,nxt[cnt]=head[x],head[x]=cnt;
}
inline void lnk(RG int x,RG int y,RG int z,RG double u) {
Addedge(x,y,z,u),Addedge(y,x,0,-u);
}
inline bool spfa() {
for(RG int i=S; i<=T; i++) dis[i]=Inf,W[i]=0;
RG int t=0,sum=1;
q[0]=S,W[S]=1,dis[S]=0;
while(t<sum) {
RG int x=q[t++];
W[x]=0;
for(RG int i=head[x];i;i=nxt[i]) {
RG int y=to[i];
if(s[i]&&dis[y]-(dis[x]+cc[i])>=eps) {
dis[y]=dis[x]+cc[i];
fa[y]=i;
if(!W[y]) W[y]=1,q[sum++]=y;
}
}
}
if(dis[T]==Inf) return 0;
RG int f=Inf;
for(RG int i=fa[T];i;i=fa[to[i^1]]) f=min(f,s[i]);
for(RG int i=fa[T];i;i=fa[to[i^1]]) s[i]-=f,s[i^1]+=f;
cost+=dis[T]*f;
return 1;
}
inline void Maxcost() {
while(spfa());
}
inline bool check(RG double mid){
cnt=1;memset(head,0,sizeof(head));
for(RG int i=1;i<=n;i++)
for(RG int j=1;j<=n;j++)
lnk(i,j+n,1,-(a[i][j]-mid*b[i][j]));
for(RG int i=1;i<=n;i++) lnk(S,i,1,0),lnk(i+n,T,1,0);
cost=0;Maxcost();cost=-cost;
return cost-0>=eps;
}
main() {
freopen("1.in","r",stdin);
n=gi();S=0,T=2*n+1;
for(RG int i=1;i<=n;i++)
for(RG int j=1;j<=n;j++)
a[i][j]=gi();
for(RG int i=1;i<=n;i++)
for(RG int j=1;j<=n;j++)
b[i][j]=gi();
double l=0,r=10000.0,ans=0;
while(r-l>=eps){
double mid=(l+r)/2;
if(check(mid)) l=mid,ans=mid;
else r=mid;
}
printf("%.6f",ans);
}
bzoj 4819: [Sdoi2017]新生舞会的更多相关文章
- BZOJ.4819.[SDOI2017]新生舞会(01分数规划 费用流SPFA)
BZOJ 洛谷 裸01分数规划.二分之后就是裸最大费用最大流了. 写的朴素SPFA费用流,洛谷跑的非常快啊,为什么有人还T成那样.. 当然用二分也很慢,用什么什么迭代会很快. [Update] 19. ...
- BZOJ 4819 [Sdoi2017]新生舞会 ——费用流 01分数规划
比值最大 分数规划 二分答案之后用费用流进行验证. 据说标称强行乘以1e7换成了整数的二分. 不过貌似实数二分也可以过. #include <map> #include <cmath ...
- bzoj 4819: [Sdoi2017]新生舞会【二分+最小费用最大流】
如果\( b[i]==0 \)那么就是裸的费用流/KM,当然KM快一些但是为什么不写KM呢因为我不会打板子了 考虑二分答案,那么问题变成了判定问题. \[ ans=\frac {a_1+a_2+... ...
- 【BZOJ 4819】 4819: [Sdoi2017]新生舞会 (0-1分数规划、二分+KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 601 Solved: 313 Description 学校 ...
- 4819: [Sdoi2017]新生舞会(分数规划)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1031 Solved: 530[Submit][Statu ...
- 4819: [Sdoi2017]新生舞会 分数规划
题目 https://www.lydsy.com/JudgeOnline/problem.php?id=4819 思路 分数规划的模板题?(好菜呀) 假如n=3吧(懒得写很长的式子) \(c=\fra ...
- [BZOJ4819][SDOI2017]新生舞会(分数规划+费用流,KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1097 Solved: 566[Submit][Statu ...
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...
- BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流
BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞 ...
随机推荐
- 详解卷积神经网络(CNN)在语音识别中的应用
欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 作者:侯艺馨 前言 总结目前语音识别的发展现状,dnn.rnn/lstm和cnn算是语音识别中几个比较主流的方向.2012年,微软邓力和俞栋老 ...
- 题目1083:特殊乘法-九度oj
题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5 输入: 两个小于1000000000的 ...
- Cell重用时数据混乱的管理方法
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的UITableViewCell,可以让UITableViewCell响应一些点击 ...
- 数据库服务器---Tps
事务处理系统:Transactionprocessingsystems(TPS) 提高事务处理效率与保证其正确性 在数据(信息)发生处将它们记录下来 通过OLTP产生新的信息 将信息保存到数据库中供其 ...
- php IP转换整形(ip2long)
如何将四个字段以点分开的IP网络址协议地址转换成整数呢?PHP里有这么一个函数ip2long.比如 <?php echo ip2long("10.2.1.3"); ?> ...
- 纯css美化单选、复选框
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- maven jetty struts异常 There is no Action mapped for namespace [/] and action name [] associated with context path
毕业设计中用maven jetty插件调试时,struts出现这个错误,直接http://localhost:8080 无法进入默认主页,但换tomcat就没问题,最后在这篇文章找到答案 http:/ ...
- OJ随笔——【1088-N!】——同余定理
题目如下: Description 请求N!(N<=10000),输出结果对10007取余输入每行一个整数n,遇到-1结束.输出每行一个整数,为对应n的运算结果. Sample Input ...
- struts2捕获action类异常
首先是STRUTS.XML的配置.重点在于配置文件: <!-- struts2捕获action类异常 --> <global-results> <resu ...
- [Sqoop]利用sqoop对mysql运行DML操作
业务背景 利用sqoop对mysql进行查询.加入.删除等操作. 业务实现 select操作: sqoop eval \ --connect jdbc:mysql://127.0.0.1:3306/m ...