codevs 5965 [SDOI2017]新生舞会
分数规划的裸题。
不会分数规划的OIer。百度:胡伯涛《最小割模型在信息学竞赛中的应用》
- /*
- TLE1:
- last:add(i,j+n,1e9,(real)((real)a[i][j]-ans*(real)b[i][j]));
- now :add(i,j+n,1,(real)((real)a[i][j]-ans*(real)b[i][j]));
- TLE2:
- last:real l=eps,r=(real)u/(real)v,mid,ans=0,now;
- now :real l=0,r=(real)(u+v-1)/(real)v,mid,ans=0,now;
- TLE3:
- last:struct edge{int v,next;real cost,cap;}e[N<<1];
- now :to[N],next[N],cap[N];real cost[N];(结构体跑得慢)
- TLE4:
- last:typedef long double real;
- now :typedef double real;
- */
- #include<cmath>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #define set(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
- using namespace std;
- const int N=1e5+;
- const int Z=;
- typedef long double real;
- const real eps=1e-;
- int n,m,S,T,a[Z][Z],b[Z][Z];
- int to[N],next[N],cap[N];real cost[N];int tot=,head[N];
- real dis[N];int q[N],pre[N];bool vis[N];
- inline int read(){
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- void add(int x,int y,int z,real Cost){
- to[++tot]=y;cap[tot]=z;cost[tot]=Cost;next[tot]=head[x];head[x]=tot;
- to[++tot]=x;cap[tot]=;cost[tot]=-Cost;next[tot]=head[y];head[y]=tot;
- }
- bool spfa(){
- memset(vis,,sizeof vis);
- for(int i=;i<=T+;i++) dis[i]=-1e9;
- unsigned short h=,t=;q[t]=S;dis[S]=;
- while(h!=t){
- int x=q[++h];vis[x]=;
- for(int i=head[x];i;i=next[i]){
- if(cap[i]>&&dis[to[i]]<dis[x]+cost[i]){
- dis[to[i]]=dis[x]+cost[i];
- pre[to[i]]=i;
- if(!vis[to[i]]){
- vis[to[i]]=;
- q[++t]=to[i];
- }
- }
- }
- }
- return dis[T]>-1e9;
- }
- real augment(){
- // int flow=1e9;
- // for(int i=T;i!=S;i=to[pre[i]^1]) flow=min(flow,cap[pre[i]]);
- int flow=;
- for(int i=T;i!=S;i=to[pre[i]^]){
- cap[pre[i]]-=flow;
- cap[pre[i]^]+=flow;
- }
- return dis[T]*flow;
- }
- real mapping(real ans){
- tot=;S=;T=n<<|;
- memset(head,,sizeof head);
- for(int i=;i<=n;i++) add(S,i,,),add(i+n,T,,);
- for(int i=;i<=n;i++){
- for(int j=;j<=n;j++){
- add(i,j+n,,(real)((real)a[i][j]-ans*(real)b[i][j]));
- }
- }
- real res=0.0;
- while(spfa()) res+=augment();
- return res;
- }
- int cmp(real x){
- if(fabs(x)<eps) return ;
- return x>?:-;
- }
- void work1(){
- tot=;S=;T=n<<|;
- memset(head,,sizeof head);
- for(int i=;i<=n;i++) add(S,i,,),add(i+n,T,,);
- for(int i=;i<=n;i++){
- for(int j=;j<=n;j++){
- add(i,j+n,,(real)a[i][j]);
- }
- }
- real res=0.0;
- while(spfa()) res+=augment();
- res/=1.0*n;
- printf("%.6lf\n",(double)res);
- }
- int main(){
- set(ball);
- n=read();
- int u=,v=;
- for(int i=,t;i<=n;i++){
- t=;
- for(int j=;j<=n;j++){
- a[i][j]=read();
- t=max(t,a[i][j]);
- }
- u+=t;
- }
- bool f=;
- for(int i=,t;i<=n;i++){
- t=1e9;
- for(int j=;j<=n;j++){
- b[i][j]=read();
- t=min(t,b[i][j]);
- if(b[i][j]!=) f=;
- }
- v+=t;
- }
- if(f){work1();return ;}
- real l=,r=(real)(u+v-)/(real)v,mid,ans=,now;
- while(l+eps<r){
- mid=(l+r)/2.0;
- now=mapping(mid);
- if(cmp(now)==){printf("%.6lf\n",(double)mid);return ;}
- if(cmp(now)>) l=mid;
- else r=mid;
- }
- printf("%.6lf\n",(double)l);
- fclose(stdin);
- fclose(stdout);
- return ;
- }
codevs 5965 [SDOI2017]新生舞会的更多相关文章
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...
- BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流
BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞 ...
- 洛谷 P3705 [SDOI2017]新生舞会 解题报告
P3705 [SDOI2017]新生舞会 题目描述 学校组织了一次新生舞会,\(Cathy\)作为经验丰富的老学姐,负责为同学们安排舞伴. 有\(n\)个男生和\(n\)个女生参加舞会买一个男生和一个 ...
- 【BZOJ 4819】 4819: [Sdoi2017]新生舞会 (0-1分数规划、二分+KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 601 Solved: 313 Description 学校 ...
- 【BZOJ4819】[Sdoi2017]新生舞会 01分数规划+费用流
[BZOJ4819][Sdoi2017]新生舞会 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会 买一个男生和一个女 ...
- [BZOJ4819][SDOI2017]新生舞会(分数规划+费用流,KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1097 Solved: 566[Submit][Statu ...
- 【算法】01分数规划 --- HNOI2009最小圈 & APIO2017商旅 & SDOI2017新生舞会
01分数规划:通常的问法是:在一张有 \(n\) 个点,\(m\) 条边的有向图中,每一条边均有其价值 \(v\) 与其代价 \(w\):求在图中的一个环使得这个环上所有的路径的权值和与代价和的比率最 ...
- 4819: [Sdoi2017]新生舞会(分数规划)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1031 Solved: 530[Submit][Statu ...
- 题解:SDOI2017 新生舞会
题解:SDOI2017 新生舞会 Description 学校组织了一次新生舞会,Cathy 作为经验丰富的老学姐,负责为同学们安排舞伴. 有 \(n\) 个男生和 \(n\) 个女生参加舞会.一个男 ...
随机推荐
- Android编程的写法规范
一.获取View对象 1.private EditText m_txtSmsPhone = null;//定义一个EditText控件的调用对象 m_表示为View对象 txt表示文本框 2.在pro ...
- 读写SQLServer数据库中的image类型数据(简单)
1.将double类型的数据存储于image类型的变量中: (1). char *CManualForecastResultBll::DoubleArray2Binary(std::vector< ...
- ASIHTTPRequest 简单使用
ASIHTTPResquest 框架功能强大,应用非常多. 曾经写过ASIHTTPResquest的导入,如今就看一下基本使用 记一下当中基础的操作: 1.发送同步请求: NSURL * url = ...
- php getallheaders使用注意事项
This function is an alias for apache_request_headers(). Please read the apache_request_headers() doc ...
- Atitit.数据库事务隔离级别 attilax 总结
Atitit.数据库事务隔离级别 1. 事务隔离级别的作用 1 2. 在的隔离级别 2 3. 常见数据库的默认管理级别 3 1. 事务隔离级别的作用 较低的隔离级别可以增强许多用户同时访问数据的能力, ...
- 【Android】14.3 浏览手机中的所有文件夹和文件
分类:C#.Android.VS2015: 创建日期:2016-02-27 一.简介 前面我们了解了内部存储.外部存储的含义,用一句话说,内部存储实际上是保存在"data"文件夹下 ...
- bazel-编译多目标
demo2 使用bazel编译多目标示例,一个bianry,一个library. demo2目录树 ── demo2 ├── app │ ├── BUILD │ ├── func.cpp ...
- 第7章 Iptables与Firewalld防火墙。
第7章 Iptables与Firewalld防火墙. Chapter7_听较强节奏的音乐能够让您更长时间的投入在学习中. <Linux就该这么学> 00:00/00:00 ...
- QQ连连看-外挂
QQ连连看-外挂 2014-11-06 参考 [1] [视频教程] c语言实践课程之qq连连看辅助开发 [2] CE工具下载 [3] [原创]qq连连看外挂制作详解
- lua工具库penlight--07函数编程(二)
列表压缩 列表压缩是以紧凑的方式通过指定的元素创建表.在 Python里,你可以说: ls = [x for x in range(5)] # == [0,1,2,3,4] 在 Lua,使用pl.c ...