2014 西安 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的更多相关文章
- Gym - 100548C The Problem Needs 3D Arrays
Problem C. The Problem Needs 3D Arrays Time Limit: 6000MS Memory Limit: 262144KB 64bit IO Format: ...
- 14西安区域赛C - The Problem Needs 3D Arrays
最大密度子图裸题,详情请见胡博涛论文: https://wenku.baidu.com/view/986baf00b52acfc789ebc9a9.html 不加当前弧优化t到死= = //#prag ...
- Uvalive 7037 The Problem Needs 3D Arrays(最大密度子图)
题意:给一段子序列,定义密度:子序列中的逆序对数/子序列的长度 求这个序列的对大密度. 分析:将序列中的每个位置视作点,逆序对\(<i,j>\)之间表示点i与点j之间有一条无向边.所以就转 ...
- Gym - 100548C The Problem Needs 3D Arrays (最大密度子图)
TK在大多数 Unix平台.Windows平台和Macintosh系统都是预装好的,TKinter 模块是 Tk GUI 套件的标准Python接口.可实现Python的GUI编程. Tkinter模 ...
- UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)
题目链接 题意 给出n个点,每个点有一个值,现在要选择一些点的集合,使得(选择的点生成的逆序对数目)/(选择的点的数量)的比率最大. 思路 点与点之间生成一个逆序对可以看做是得到一个边,那么就是分数规 ...
- 2014西安现场赛F题 UVALA 7040
地址 题意:求在m种颜色中挑选k种颜色,给n个花朵涂色有几种方法. 分析:画图可以发现,基本的公式就是k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总颜色数不超过k种,并没有保证恰好出现k种 ...
- Last Defence (2014 西安现场赛)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K Last Defence Time Limit:3000MS ...
- 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 ...
- 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 ...
随机推荐
- nginx 301跳转https后post请求失效问题解决
app本地请求是http端口,后来升级https强制301跳转,设置如下 server { listen 80; server name www.XXX.com; rewrite ^/(.*)$ ht ...
- 【JDK】JDK源码分析-HashMap(1)
概述 HashMap 是 Java 开发中最常用的容器类之一,也是面试的常客.它其实就是前文「数据结构与算法笔记(二)」中「散列表」的实现,处理散列冲突用的是“链表法”,并且在 JDK 1.8 做了优 ...
- 大型系列课程之-七夕告白之旅vbs篇
也许,世间所有的美好的东西,都是需要仪式感的,遇到了一年一度的七夕节,怎么过这个节日,成了很多心中有爱的人关注的事情,七夕不浪漫,人间不值得,七夕,发源于中国,这个美好的节日,来自动人的神话故事传说牛 ...
- 什么?小程序实时语音识别你还在痛苦的对接科大讯飞?百度Ai识别?
前言 微信小程序,说不上大火,但是需求还是不少的.各大企业都想插一足 于是前端同学就有事情做了. 需求 我需要录音 我边说话边识别,我要同声传译,我要文字转语音,还要萝莉音 我:??? 正文 一开始, ...
- Windows的 IIS 部署django项目
Windows的 IIS 部署django项目 1.安装Windows的IIS 功能(win10为例): (1)进入控制面板 :选择大图标 进入程序和功能 (2)启用或者关闭Windows功能 ...
- aes秘钥限制问题解决办法
在oarcle jdk1.8上执行256位的aes秘钥加密报错如下: java.lang.RuntimeException: java.security.InvalidKeyException: Il ...
- Web前端开发工程师课程大纲
PHP程序员雷雪松整理出来的一套独一无二的Web前端开发课程.本套Web前端开发课程专门为想励志成为优秀web前端工程师的学习者而总结归纳的,本套Web前端课程舍弃了一些不常用的即将废弃的HTML标签 ...
- Streaming+Sparksql使用sql实时分析 rabbitmq+mongodb+hive
SparkConf sparkConf = new SparkConf()//此处使用一个链接切记使用一个链接否则汇报有多个sparkcontext错误 .setAppName("Spark ...
- Python.append()与Python.extend()的区别
lst=[1,2] >>>[1,2] lst.append([3,4]) >>>[1, 2, [3, 4]] lst.extend([3,4]) >>& ...
- Python依赖包整体迁移方法
1.新建site-packages目录,进入到site-packages目录下: 2.在site-packages目录下执行pip freeze >requirements.txt: 3.查看r ...