BZOJ 2395 [Balkan 2011]Time is money
题面
题解
将\(\sum_i c_i\)和\(\sum_i t_i\)分别看做分别看做\(x\)和\(y\),投射到平面直角坐标系中,于是就是找\(xy\)最小的点
于是可以先找出\(x\)最小的点\(\mathrm{A}\)和\(y\)最小的点\(\mathrm{B}\),然后找到在\(\mathrm{AB}\)左下方的最远的点\(\mathrm{C}\),如图所示:

即\(\overrightarrow{\mathrm{AB}} \times \overrightarrow{\mathrm{AC}}\)最小(因为\(\overrightarrow{\mathrm{AB}} \times \overrightarrow{\mathrm{AC}} \leq 0\))
\because \overrightarrow{\mathrm{AB}} \times \overrightarrow{\mathrm{AC}} &= (x_{\mathrm{B}} - x_{\mathrm{A}})(y_{\mathrm{C}} - y_{\mathrm{A}}) - (y_{\mathrm{B}} - y_{\mathrm{A}})(x_\mathrm{C} - x_\mathrm{A}) \\
&= (x_\mathrm B - x_\mathrm A) \times y_\mathrm C + (y_\mathrm A - y_\mathrm B) \times x_\mathrm C + y_\mathrm B x_\mathrm A - x_\mathrm B y_\mathrm A
\end{aligned}
\]
然后发现只要\((x_\mathrm B - x_\mathrm A) \times y_\mathrm C + (y_\mathrm A - y_\mathrm B) \times x_\mathrm C\)最小即可。
将每条边的权值改为\(\mathrm{g}[i][j] = (y_\mathrm A - y_\mathrm B) \times c[i][j] + (x_\mathrm B - x_\mathrm A)\times t[i][j]\),跑一遍最小生成树就可以得出答案了。
找到\(\mathrm C\)之后用叉积判断一下\(\mathrm C\)是不是在\(\mathrm{AB}\)的下方,如果是的话,就递归处理\(\mathrm{AC, CB}\)
复杂度?O(能过)
因为\(\mathrm{A, B, C}\)肯定在凸包上,又\(n\)个点的凸包期望点数为\(\sqrt{\ln n}\),
于是复杂度为\(\mathrm{O}(\sqrt{\ln n!} \times n^2)\)或者\(\mathrm{O}(\sqrt{\ln n!} \times m\log m)\)
代码
#include<cstdio>
#include<cctype>
#include<algorithm>
#define RG register
const int N(210), INF(1e9);
struct vector { int x, y; };
vector ans = (vector) {INF, INF};
inline vector operator - (const vector &lhs, const vector &rhs)
{ return (vector) {lhs.x - rhs.x, lhs.y - rhs.y}; }
inline int operator * (const vector &lhs, const vector &rhs)
{ return lhs.x * rhs.y - lhs.y * rhs.x; }
int g[N][N], f[N][N], dis[N], c[N][N], t[N][N], cdis[N], tdis[N], vis[N], n, m;
vector prim(int valx, int valy)
{
for(RG int i = 1; i <= n; i++)
for(RG int j = 1; j <= n; j++)
if(f[i][j]) g[i][j] = valx * c[i][j] + valy * t[i][j];
std::fill(dis + 1, dis + n + 1, INF);
std::fill(vis + 1, vis + n + 1, 0);
dis[1] = cdis[1] = tdis[1] = 0;
vector res = (vector) {0, 0};
for(RG int i = 1; i <= n; i++)
{
int _min = INF, x = -1;
for(RG int j = 1; j <= n; j++)
if(_min > dis[j] && (!vis[j])) _min = dis[j], x = j;
if(_min == INF) break; vis[x] = 1;
res.x += cdis[x], res.y += tdis[x];
for(RG int j = 1; j <= n; j++) if(f[x][j])
if(dis[j] > g[x][j]) dis[j] = g[x][j],
cdis[j] = c[x][j], tdis[j] = t[x][j];
}
long long sum = 1ll * res.x * res.y, _min = 1ll * ans.x * ans.y;
if(sum < _min || (sum == _min && res.x < ans.x)) ans = res;
return res;
}
void solve(const vector &A, const vector &B)
{
vector C = prim(A.y - B.y, B.x - A.x);
if((B - A) * (C - A) >= 0) return;
solve(A, C); solve(C, B);
}
int main()
{
scanf("%d%d", &n, &m);
for(RG int i = 1, x, y, _c, _t; i <= m; i++)
scanf("%d%d%d%d", &x, &y, &_c, &_t), ++x, ++y,
c[x][y] = c[y][x] = _c, t[x][y] = t[y][x] = _t,
f[x][y] = f[y][x] = 1;
vector A = prim(1, 0), B = prim(0, 1);
solve(A, B); printf("%d %d\n", ans.x, ans.y);
return 0;
}
BZOJ 2395 [Balkan 2011]Time is money的更多相关文章
- bzoj 2395 [Balkan 2011]Timeismoney——最小乘积生成树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2395 如果把 \( \sum t \) 作为 x 坐标,\( \sum c \) 作为 y ...
- BZOJ 2395 [Balkan 2011]Timeismoney(最小乘积生成树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2395 [题目大意] 给出一张无向图,每条边上有a,b两个值,求生成树, 使得suma* ...
- bzoj 2395: [Balkan 2011]Timeismoney【计算几何+最小生成树】
妙啊,是一个逼近(?)的做法 把两个值最为平面上的点坐标,然后答案也是一个点. 首先求出可能是答案的点xy分别是按照c和t排序做最小生成树的答案,然后考虑比这两个点的答案小的答案,一定在xy连线靠近原 ...
- @bzoj - 2395@ [Balkan 2011]Timeismoney
目录 @description@ @solution@ @accepted code@ @details@ @description@ 有n个城市(编号从0..n-1),m条公路(双向的),从中选择n ...
- 【BZOJ】2395: [Balkan 2011]Timeismoney
题解 最小乘积生成树! 我们把,x的总和和y的总和作为x坐标和y左边,画在坐标系上 我们选择两个初始点,一个是最靠近y轴的A,也就是x总和最小,一个是最靠近x轴的B,也就是y总和最小 连接两条直线,在 ...
- [BZOJ 2299][HAOI 2011]向量 题解(裴蜀定理)
[BZOJ 2299][HAOI 2011]向量 Description 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), ...
- 【BZOJ2395】[Balkan 2011]Timeismoney
[BZOJ2395][Balkan 2011]Timeismoney 题面 \(darkbzoj\) 题解 如果我们只有一个条件要满足的话直接最小生成树就可以了,但是现在我们有两维啊... 我们将每个 ...
- [BZOJ 2395] Time is money
Link: BZOJ 2395 传送门 Solution: 算是一类比较经典的模型: 即对于一类经典问题,每点由1个权值化为2个权值,最终求$sigma(val_1)*sigma(val_2)$ 对于 ...
- [BZOJ 2301] [HAOI 2011] Problem b (莫比乌斯反演)(有证明)
[BZOJ 2301] [HAOI 2011] Problem b (莫比乌斯反演)(有证明) 题面 T组询问,每次给出a,b,c,d,k,求\(\sum _{i=a}^b\sum _{j=c}^d[ ...
随机推荐
- Html.Partial()传值的问题
@Html.Partial("Test", Model, new ViewDataDictionary { { "a", "b" } }); ...
- [翻译] CRPixellatedView-用CIPixellate滤镜动态渲染UIView
CRPixellatedView-用CIPixellate滤镜动态渲染UIView https://github.com/chroman/CRPixellatedView 本人测试的效果: Usage ...
- Linux tree命令详解
tree: 查看目录结构 tree常见命令参数 usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [- ...
- symfony学习笔记1—简介
1.symfony快速入门还是先看代码结构把,这个是拿到代码的第一印象,app/:整个应用的配置,模版,translations,这个可能是多语言文件什么,src/:项目php文件,vendor/:第 ...
- Linux常用命令笔记总结(待补充)
问题实际场景:遇到告警磁盘利用率不足,检查根目录下各文件大小 Linux查看磁盘利用率 df –h 查找磁盘占用情况 find / -size +100M 从根目录往下找大于100M大小的文件 du ...
- 关于使用JQ scrollTop方法进行滚动定位
没图我说个锤子,先来个自拍镇楼. 又到了每周周五总结时间.我广州刘德华又来讲故事了.这一周没啥任务,就一个任务,产品口头交代了两句,也没有psd没有设计图没有样式.自由发挥,你自己敲代码做个作品出来. ...
- python多进程(三)
消息队列 消息队列”是在消息的传输过程中保存消息的容器. 消息队列最经典的用法就是消费者和生成者之间通过消息管道来传递消息,消费者和生成者是不通的进程.生产者往管道中写消息,消费者从管道中读消息. ...
- 新手学Linux:在VMware14中安装CentOS7详细教程
VMware Workstation14安装CentOS7.0 详情教程 1.准备工作 a)下载VMware workstation14 b)下载CentOS7 c)下载SSH Secure Shel ...
- 基于easyui开发Web版Activiti流程定制器详解(二)——文件列表
上一篇我们介绍了目录结构,这篇给大家整理一个文件列表以及详细说明,方便大家查找文件. 由于设计器文件主要保存在wf/designer和js/designer目录下,所以主要针对这两个目录进行详细说明. ...
- ijcai statistics