Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution

题目链接:https://atcoder.jp/contests/cf16-exhibition-final/tasks/cf16_exhibition_final_e

洛谷链接:https://www.luogu.com.cn/problem/AT2230

模拟赛出了这道题,赛时觉得这题是最简单的一题,想了很久但是第一个结论就想错了,知道是状压但始终设不出来状态。

Solution

我们思考答案是怎样得到的。显然由一些连通块组成,那么思路就是分别考虑每个连通块的最优解,然后\(O(3^n)\)枚举子集状压合并答案。

想到这一步之后就很简单了。对于一个连通块,我们可以求出其最小生成树,假设最小生成树的各边权之和为\(E\),连通块内水的总量为\(A\),连通块的点数为\(V\),那么这个连通块的答案就是\(\frac{A-E}{V}\)。

连通块的最小生成树可以\(O(2^n n^2)\text{DP}\)求出。于是总复杂度为\(O(2^n n^2 + 3^n)\)。

点我看代码
#include <cstdio>
#include <iostream>
#include <cmath>
#define db double
using namespace std;
inline void read(int &x) {
x = 0; int f = 0; char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
if(f) x = ~x + 1;
}
const int N = 16;
const db inf = 1e18;
int n;
struct City {
db x, y, a;
}p[N];
db dis[N][N];
inline db sqr(db x) {return x * x;}
db f[1 << N], g[1 << N];
inline db popcount(int x) {int res = 0; while(x) ++res, x &= x - 1; return res;}
inline void update(db &x, db y) {x = min(x, y);}
int main() {
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
scanf("%d",&n);
for(int i = 1; i <= n; ++i) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].a);
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j)
dis[i][j] = dis[j][i] = sqrt(sqr(p[i].x - p[j].x) + sqr(p[i].y - p[j].y));
for(int i = 0; i < 1 << n; ++i) f[i] = inf;
for(int i = 1; i <= n; ++i) f[1 << i - 1] = 0;
for(int s = 1; s < 1 << n; ++s)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if((s & (1 << i - 1)) && !(s & (1 << j - 1))) update(f[s | (1 << j - 1)], f[s] + dis[i][j]);
for(int s = 1; s < 1 << n; ++s) {
for(int i = 1; i <= n; ++i) if(s & (1 << i - 1)) g[s] += p[i].a;
g[s] -= f[s], g[s] /= popcount(s);
for(int t = (s - 1) & s; t; t = (t - 1) & s)
g[s] = max(g[s], min(g[t], g[s ^ t]));
}
printf("%.12lf\n",g[(1 << n) - 1]);
}

Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution的更多相关文章

  1. CODE FESTIVAL 2016 Grand Final 题解

    传送门 越学觉得自己越蠢--这场除了\(A\)之外一道都不会-- \(A\) 贪心从左往右扫,能匹配就匹配就好了 //quming #include<bits/stdc++.h> #def ...

  2. Atcoder CODE FESTIVAL 2016 Final G - Zigzag MST[最小生成树]

    题意:$n$个点,$q$次建边,每次建边选定$x,y$,权值$c$,然后接着$(y,x+1,c+1),(x+1,y+1,c+2),(y+1,x+2,c+3),(x+2,y+2,c+4)\dots$(画 ...

  3. Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations

    题意: 对于一个长度为n的排列P,如果P在所有长度为n的排列中,按照字典序排列后,在第s位,则P的value为s 现在给出一个长度为n的排列P,P有一些位置确定了,另外一些位置为0,表示不确定. 现在 ...

  4. 【AtCoder】CODE FESTIVAL 2016 qual A

    CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...

  5. 【AtCoder】CODE FESTIVAL 2016 qual B

    CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...

  6. 【AtCoder】CODE FESTIVAL 2016 qual C

    CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...

  7. [AtCoder Code Festival 2017 QualB D/At3575] 101 to 010 - dp

    [Atcoder Code Festival 2017 QualB/At3575] 101 to 010 有一个01序列,每次可以选出一个101,使其变成010,问最优策略下能操作几次? 考虑像 11 ...

  8. @atcoder - CODE FESTIVAL 2017 Final - J@ Tree MST

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 个点,第 i 点有一个点权 Xi,再给定一棵边带权的树 ...

  9. CODE FESTIVAL 2016 Final 题解

    传送门 \(A\) 什么玩意儿-- const char c[]={"snuke"}; char s[15];int n,m; int main(){ scanf("%d ...

随机推荐

  1. qbxt五一数学Day1

    目录 I. 基础知识 1. 带余除法(小学) 1. 定义 2. 性质 2. 最大公约数(gcd)/ 最小公倍数(lcm) 1. 定义 2. 性质 3. 高精度 II. 矩阵及其应用 1. 定义 2. ...

  2. linux安全之网络设置

    可以通过/etc/sysctl.conf控制和配置Linux内核及网络设置. # 避免放大攻击 net.ipv4.icmp_echo_ignore_broadcasts = 1 # 开启恶意icmp错 ...

  3. 从RabbitMQ平滑迁移到RocketMQ技术实战

    作者:vivo 互联网中间件团队- Liu Runyun 大量业务使用消息中间件进行系统间的解耦.异步化.削峰填谷设计实现.公司内部前期基于RabbitMQ实现了一套高可用的消息中间件平台.随着业务的 ...

  4. 笃情开源:我和 Apache DolphinScheduler 社区的故事

    背景 本文的主人翁是 2 次飞机参会现场交流,四天研究就把 DolphinScheduler 用上生产的来自车联网行业的大数据 boy - 黄立同学.怎么样,听起来是不是有点 crazy?下面就来看看 ...

  5. JVM 系列(4)一看就懂的对象内存布局

    请点赞关注,你的支持对我意义重大. Hi,我是小彭.本文已收录到 GitHub · AndroidFamily 中.这里有 Android 进阶成长知识体系,有志同道合的朋友,关注公众号 [彭旭锐] ...

  6. SQL SERVER数据库服务器CPU不能全部利用原因分析

    背景 客户凌晨把HIS数据库迁移到配置更高的新服务器,上午业务高峰时应用非常缓慢,严重影响到业务运行.   1.现象 通过SQL专家云实时可视化界面看到大量的绿点,绿点表示会话在等待某项资源,绿点越大 ...

  7. Warning Please make sure the network configuration is correct!( iaas-install-mysql.sh 脚本)

    解读先电2.4版 iaas-install-mysql.sh 脚本 基础服务的操作命令已经编写成shell脚本,通过脚本进行一键安装.如下: # Controller节点 安装 执行脚本iaas-in ...

  8. java学习第三天常用类.day12

    String String 类是不可改变的,所以你一旦创建了 String 对象,那它的值就无法改变了 如果需要对字符串做很多修改,那么应该选择使用 StringBuffer & String ...

  9. java学习第一天.day04

    顺序结构 代码里没有流程控制,程序是按照书写的格式从上而下一行一行执行的, 一条语句执行完之后继续执行下一条语句,中间没有判断和跳转,直到程序的结束. 选择结构 选择结构也被称为分支结构.代码根据逻辑 ...

  10. cad开发动态块对应的界面

    为了使设计人员更加容易的操作动态块, 应经可能对动态块的制作制定相关的规范, 如动态块的属性 => 类的属性 动态块操作名称(作为变量名,后台数据库的字段) 动态块操作描述  (作为注释,后台数 ...