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[ ...
随机推荐
- 使用SharpZipLib压缩与解压文件
using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; using System.IO; ...
- android-eclips中logcat不显示信息的问题解决
time:2015/11/20 1. logcat窗口不显示问题 解决: 参考[1] 2. logcat中不显示信息 (1)红米手机 (2)解决问题 * 有些文章提到重启eclipse,或者重启手机. ...
- php安装--php-5.3.28
PHP的整合使用: 一.下载php源码包:https://pan.baidu.com/s/1Cied8ozHez4xJ9l1HQ7pKQ 二.把源码包放到/usr/src目录 三.解压源码包并进入目录 ...
- 资料整理,SQL Server ,面试前复习笔记
T-SQL 要掌握的知识点分类 SQL 面向数据库执行查询 SQL 从数据库取回数据 SQL 在数据库中插入新的记录 SQL 更新数据库中的数据 SQL 从数据库删除记录 SQL 创建新数据库 SQL ...
- RTCM32转码至RTCM23,再次测试,一些收获
RTCM32是2013年发布的,RTCM23是2001年发布,两者相隔十多年,某些软件已经不支持RTCM32的解码.故在此对RTCM32的编码进行转换,使用2018年4月9日天宝接收机数据.编码格式为 ...
- casperjs,phantomjs,slimerjs and spooky
1.casperjs http://casperjs.org/ CasperJS is a navigation scripting & testing utility for Phantom ...
- CentOS 7下启动、关闭、重启、查看MySQL服务
1.启动命令 [root@xufeng Desktop]# service mysqld startRedirecting to /bin/systemctl start mysqld.service ...
- 7、Android---网络技术
玩手机不能上网是单机的时代 而且现在的流量也出了无限使用 几乎网络离不开人们的日常生活 7.1.WebView的用法 遇到一些特殊的请求 在程序中展示一些网页 加载和显示网页都是浏览器的任务 在不打开 ...
- mongodb的学习-5-概念解析
http://www.runoob.com/mongodb/mongodb-databases-documents-collections.html mongodb中基本的概念是文档.集合.数据库 S ...
- Google 地图切片URL地址解析
一.Google地图切片的投影方式及瓦片索引机制 1.地图投影 Google地图采用的是Web墨卡托投影(如下图),为了方便忽略了两极变形较大的地区,把世界地图做成了一个边长等于赤道周长的正方形(赤道 ...