Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution
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的更多相关文章
- CODE FESTIVAL 2016 Grand Final 题解
传送门 越学觉得自己越蠢--这场除了\(A\)之外一道都不会-- \(A\) 贪心从左往右扫,能匹配就匹配就好了 //quming #include<bits/stdc++.h> #def ...
- 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$(画 ...
- Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations
题意: 对于一个长度为n的排列P,如果P在所有长度为n的排列中,按照字典序排列后,在第s位,则P的value为s 现在给出一个长度为n的排列P,P有一些位置确定了,另外一些位置为0,表示不确定. 现在 ...
- 【AtCoder】CODE FESTIVAL 2016 qual A
CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...
- 【AtCoder】CODE FESTIVAL 2016 qual B
CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...
- 【AtCoder】CODE FESTIVAL 2016 qual C
CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...
- [AtCoder Code Festival 2017 QualB D/At3575] 101 to 010 - dp
[Atcoder Code Festival 2017 QualB/At3575] 101 to 010 有一个01序列,每次可以选出一个101,使其变成010,问最优策略下能操作几次? 考虑像 11 ...
- @atcoder - CODE FESTIVAL 2017 Final - J@ Tree MST
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 个点,第 i 点有一个点权 Xi,再给定一棵边带权的树 ...
- CODE FESTIVAL 2016 Final 题解
传送门 \(A\) 什么玩意儿-- const char c[]={"snuke"}; char s[15];int n,m; int main(){ scanf("%d ...
随机推荐
- php去除bom头
//去掉bom头 $result = trim($result, "\xEF\xBB\xBF"); print_r(json_decode($result, true));
- linux学习随笔2之防火墙
centos7默认使用的防火墙是firewalld 查看所有打开的端口: firewall-cmd --zone=public --list-ports 更新防火墙规则: firewall-cmd - ...
- linux常见命令搜集
查找根目录下txt和pdf文件 find / \( -name "*.txt" -o -name "*.pdf" \) -print 正则查找根目录下所有的tx ...
- 5.31 NOI 模拟
\(T1\ Beauty\) \(T2\ Jump\) 考场上一开始想的是树套树,然后我看到了\(128MB,\)好 于是乎附上\(56pts\ MLE\)代码在空间\(512MB\)可以获得\(84 ...
- Dolphin Scheduler 1.2.0 部署参数分析
本文章经授权转载 1 组件介绍 Apache Dolphin Scheduler是一个分布式易扩展的可视化DAG工作流任务调度系统.致力于解决数据处理流程中错综复杂的依赖关系,使调度系统在数据处理流程 ...
- Go语言 WaitGroup 详解
你必须非常努力,才能看起来毫不费力! 微信搜索公众号[ 漫漫Coding路 ],一起From Zero To Hero ! 前言 在前面的文章中,我们使用过 WaitGroup 进行任务编排,Go语言 ...
- java学习第一天.day04
顺序结构 代码里没有流程控制,程序是按照书写的格式从上而下一行一行执行的, 一条语句执行完之后继续执行下一条语句,中间没有判断和跳转,直到程序的结束. 选择结构 选择结构也被称为分支结构.代码根据逻辑 ...
- SwiftUI实战教程-土豆List
代码库 教程中的项目代码都保存在这里:https://gitee.com/KINGWDY_admin/swiftui01 前言 在这一章节中,我们会使用List控件做一个土豆List,实现了列表填充. ...
- Linux安装GCC编译器
今天突然想到怎么样在Red Hat 8上练习C,安装GCC编译器,并运行出"hello world". 于是就有了以下操作 1 [root@localhost ~]# yum in ...
- 项目实践2:使用html和CSS实现图片轮播
好家伙, 使用html和CSS实现简单的图片切换(轮播图) 来自:(7条消息) 使用CSS实现简单的图片切换(轮播图)_LexingtonCV16的博客-CSDN博客_css实现图片切换 1.首先创建 ...