The Problem Needs 3D Arrays

题意:给你n个数, 然后1-n的数, 然后要求按顺序选出m个数, 求 逆序数/m 个数的 最大值是多少。

题解:裸的最大密度子图。逆序的2个数建边, 跑一下最大密度子图就AC了。

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = (int)1e9+;
const int N = ;
const int M = ;
double eps = 1e-;
int head[N], deep[N], cur[N];
int u[M], v[M];
int vis[N], d[N];
double w[M]; int to[M], nx[M];
int n, m, tot;
int a[N];
void add(int u, int v,double val){
w[tot] = val; to[tot] = v;
nx[tot] = head[u]; head[u] = tot++;
w[tot] = ; to[tot] = u;
nx[tot] = head[v]; head[v] = tot++;
}
int bfs(int s, int t){
queue<int> q;
memset(deep, , sizeof(int)*(n+));
q.push(s);
deep[s] = ;
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = nx[i]){
if(w[i] > && deep[to[i]] == ){
deep[to[i]] = deep[u] + ;
q.push(to[i]);
}
}
}
if(deep[t] > ) return ;
return ;
}
double Dfs(int u, int t, double flow){
if(u == t) return flow;
for(int &i = cur[u]; ~i; i = nx[i]){
if(deep[u] + == deep[to[i]] && w[i] > ){
double di = Dfs(to[i], t, min(w[i], flow));
if(di > ){
w[i] -= di, w[i^] += di;
return di;
}
}
}
return ;
} int Dinic(int s, int t){
double ans = , tmp;
while(bfs(s, t)){
for(int i = ; i <= n+; i++) cur[i] = head[i];
while(tmp = Dfs(s, t, INF)) ans += tmp;
}
return ans;
} bool check(double x){
memset(head, -, sizeof(int) * (n+));
tot = ;
int s = , t = n + ;
for(int i = ; i <= m; i++){
add(u[i], v[i], );
add(v[i], u[i], );
}
for(int i = ; i <= n; i++){
add(s, i, m);
add(i, t, m+*x-d[i]);
}
return (m*n-Dinic(s,t))/2.0 >= 1e-;
} int main(){
int T;
scanf("%d", &T);
for(int _i = ; _i <= T; _i++){
scanf("%d", &n);
for(int i = ; i <= n; i++)scanf("%d", &a[i]);
memset(d, , sizeof(int)*(n+));
m = ;
for(int i = ; i <= n; i++){
for(int j = ; j < i; j++){
if(a[j] > a[i]){
d[i]++;
d[j]++;
m++;
u[m] = i;
v[m] = j;
}
}
}
double l = , r = m, mid;
while(r - l >= eps){
mid = (l+r)/;
if(check(mid)) l = mid;
else r = mid;
}
printf("Case #%d: %.12f\n", _i, l);
//printf
} return ;
}

2014 西安 The Problem Needs 3D Arrays的更多相关文章

  1. Gym - 100548C The Problem Needs 3D Arrays

    Problem C.   The Problem Needs 3D Arrays Time Limit: 6000MS Memory Limit: 262144KB 64bit IO Format: ...

  2. 14西安区域赛C - The Problem Needs 3D Arrays

    最大密度子图裸题,详情请见胡博涛论文: https://wenku.baidu.com/view/986baf00b52acfc789ebc9a9.html 不加当前弧优化t到死= = //#prag ...

  3. Uvalive 7037 The Problem Needs 3D Arrays(最大密度子图)

    题意:给一段子序列,定义密度:子序列中的逆序对数/子序列的长度 求这个序列的对大密度. 分析:将序列中的每个位置视作点,逆序对\(<i,j>\)之间表示点i与点j之间有一条无向边.所以就转 ...

  4. Gym - 100548C The Problem Needs 3D Arrays (最大密度子图)

    TK在大多数 Unix平台.Windows平台和Macintosh系统都是预装好的,TKinter 模块是 Tk GUI 套件的标准Python接口.可实现Python的GUI编程. Tkinter模 ...

  5. UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)

    题目链接 题意 给出n个点,每个点有一个值,现在要选择一些点的集合,使得(选择的点生成的逆序对数目)/(选择的点的数量)的比率最大. 思路 点与点之间生成一个逆序对可以看做是得到一个边,那么就是分数规 ...

  6. 2014西安现场赛F题 UVALA 7040

    地址 题意:求在m种颜色中挑选k种颜色,给n个花朵涂色有几种方法. 分析:画图可以发现,基本的公式就是k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总颜色数不超过k种,并没有保证恰好出现k种 ...

  7. Last Defence (2014 西安现场赛)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K Last Defence Time Limit:3000MS ...

  8. Google Code Jam 2014 资格赛:Problem D. Deceitful War

    This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...

  9. Google Code Jam 2014 资格赛:Problem C. Minesweeper Master

    Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...

随机推荐

  1. 【Android】Field requires API level 4 (current min is 1): android.os.Build.VERSION#SDK_INT

    刚遇到了这个问题: Field requires API level 4 (current min is 1): android.os.Build.VERSION#SDK_INT 解决方法: 修改 A ...

  2. JDK的可视化工具系列 (四) JConsole、VisualVM

    JConsole: Java监视与管理控制台 代码清单1: import java.util.*; public class JConsoleDemo { static class OOMObject ...

  3. 7z 命令行方式生成自解压exe

    一.下载 7z是一个免费的工具,除了通过命令行的方式提供各种文件.压缩包相关的操作外,还提供了一种方式可以打出自解压的exe程序.该程序从运行到结束经历了三个流程: (1) 解压文件到用户临时目录: ...

  4. Go组件学习——gorm四步带你搞定DB增删改查

    1.简介 ORM Object-Relationl Mapping, 它的作用是映射数据库和对象之间的关系,方便我们在实现数据库操作的时候不用去写复杂的sql语句,把对数据库的操作上升到对于对象的操作 ...

  5. 我的第一个py爬虫-小白(beatifulsoup)

    一.基本上所有的python第一步都是安装.安装 我用到的第三方安装包(beatifulsoup4.re.requests).还要安装lxml 二.找个http开头的网址我找的是url="h ...

  6. 全屏滚动插件pagePiling.js

    全屏滚动效果是最近非常流行的网页设计形式,带给用户良好的视觉和交互体验.pagePiling.js 这款 jQuery 插件可以帮助前端开发人员轻松实现这种效果.支持所有的主流浏览器,包括IE8+,支 ...

  7. Android实现多语言so easy

    微信公众号:CodingAndroid CSDN:http://blog.csdn.net/xinpengfei521声明:本文由CodingAndroid原创,未经授权,不可随意转载! 最近,我们公 ...

  8. 解决!!-- krb5-libs.x86_64被卸载,yum不能使用,ssh不能连接

    常在河边走哪有不湿鞋,常玩服务器哪有不搞挂几台,一不小心就搞挂了 今天删除 krb5-libs.x86_64下了狠功夫..... 用了命令: rpm -e --nodeps  krb5-libs.x8 ...

  9. C#.Net实现AutoCAD块属性提取

    https://blog.csdn.net/dengyiyu/article/details/2201175 本文主要给大家介绍一下SmartSoft中用C#.Net实现AutoCAD块属性提取的方法 ...

  10. Could not determine type for java util List

    问题场景:在实体类中需要使用List集合存储字段,启动时找不到List类型 问题解决:在字段上添加@ElementColletion(targetClass=String.class)表示是一个集合映 ...