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 ...
随机推荐
- Spring的简单使用(1)
一:IOC(控制反转):它是由spring容器进行对象的创建和依赖注入,程序员使用时直接取出即可 正转:例如: Student stu=new Student(): stu.setname(" ...
- 关于MySQL function创建的限制
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. MySQL 的function创建会有各种限制,经常使用的语句的限制如下: 1.CONTAINS_DYNAMIC_SQL ...
- Spring提供的API实现文件上传
Spring为我们提供了文件上传接口MultipartRequest及其实现类StandardMultipartFile StandardMultipartFile是StandardMultipart ...
- NC20273 [SCOI2009]粉刷匠
题目链接 题目 题目描述 windy有 N 条木板需要被粉刷. 每条木板被分为 M 个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能选择一条木板上一段连续的格子,然后涂上一种颜色. 每 ...
- virtio 驱动的数据结构理解
ps:本文基于4.19.204内核 Q:vqueue的结构成员解释: A:结构如下,解析附后: struct virtqueue { struct list_head list;//caq:一个vir ...
- 二维积水(DP优化)
题面 在二向箔爆发前的时间里,宇宙中就有一个叫地球的星球,上面存在过奴隶主,后来绝迹了-- --<第三维的往事> 在这个美丽的二维宇宙中,有一个行星叫地圆.地圆有一条大陆叫美洲,上面生活着 ...
- 新年趣事之红包--"四边形"不等式优化DP
目录 题目描述 输入 输出 思路 新年趣事之红包 时间限制: 1 Sec 内存限制: 64 MB 题目描述 xiaomengxian一进门,发现外公.外婆.叔叔.阿姨--都坐在客厅里等着他呢.经过仔 ...
- Mybatis的ResultMap与limit分页查询
ResultMap主要解决的是:属性名和字段不一致 如果在pojo中设置的是一个名字,在数据库上又是另一个名字,那么查询出来的结果或者其他操作的结果就为null. //在pojo中 private S ...
- Neural ODE相关论文摘要翻译
*****仅供个人学习记录***** Neural Ordinary Differential Equations[2019] 论文地址:[1806.07366] Neural Ordinary Di ...
- 端口安全 | DHCP snooping
1.端口安全用于防止mac地址的欺骗.mac地址泛洪攻击.主要思想就是在交换机的端口下通过手工或者自动绑定mac地址,这就就只能是绑定的mac地址能够通过. 2.通过静态的端口绑定:将mac地址手工静 ...