hihocoder 1150 基站选址
来源:互联网 发布:淘宝 手机 假货 编辑:程序博客网 时间:2024/05/01 18:14
首先X,Y轴分开考虑,枚举B,对于坐标分成左边和右边,这两边都是满足凹函数的,可以三分求解,维护最小值
(不过据说这题数据很水,我模拟退火的也过了
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int N = 105;int ax[N * 10], ay[N * 10];int t, n, m, an, bn;int abss(int x) { if (x < 0) return -x; return x;}ll cal2(int u, int v, int *x) { ll ans = 0; ans += abss(u - v); for (int i = 0; i < an; i++) { int dx = u - x[i]; ans += (ll)dx * dx; } return ans;}ll cal(int l, int r, int v, int *x) { while (r - l > 2) { int midl = (l * 2 + r) / 3; int midr = (l + 2 * r) / 3; if (cal2(midl, v, x) < cal2(midr, v, x)) r = midr; else l = midl; } ll ans = (1LL<<63) - 1; for (int i = l; i <= r; i++) ans = min(ans, cal2(i, v, x)); return ans;}ll gao(int x, int y) { ll ans = 0; ans += min(cal(1, x, x, ax), cal(x, n, x, ax)); ans += min(cal(1, y, y, ay), cal(y, m, y, ay)); return ans;}int main() { int cas = 0; scanf("%d", &t); while (t--) { scanf("%d%d%d%d", &n, &m, &an, &bn); for (int i = 0; i < an; i++) scanf("%d%d", &ax[i], &ay[i]); ll ans = (1LL<<63) - 1; int x, y; for (int i = 0; i < bn; i++) { scanf("%d%d", &x, &y); ans = min(ans, gao(x, y)); } printf("Case #%d: %lld\n", ++cas, ans); } return 0;}
0 0
- hihocoder 1150 基站选址
- [hihoCoder 1150] 基站选址(几何题,中心点)
- 【hihoCoder】基站选址
- 基站选址
- 基站选址
- hihocoder 2015编程之美 资格赛 hihocoder 第三题 基站选址
- BSOJ: 2699 【ZJOI2010】基站选址
- 1835: [ZJOI2010]base 基站选址
- BZOJ1835 [ZJOI2010]base 基站选址
- [BZOJ1835][ZJOI2010]base 基站选址
- BZOJ1835 [ZJOI2010]base 基站选址
- 1835: [ZJOI2010]base 基站选址
- 1835: [ZJOI2010]base 基站选址
- ★【动态规划】【线段树】基站选址
- 2015编程之美 基站选址
- 【bzoj1835】【ZJOI2010】【基站选址】【dp+线段树】
- ZJOI 2010 基站选址 DP+SegmentTree
- 2017.5.18-24 基站选址 失败总结
- APUE 学习笔记(第四章)
- spark:学习杂记+案例--41
- 重写父类方法
- C++输入输出格式,及其他零碎知识的整合
- SHELL学习笔记1
- hihocoder 1150 基站选址
- linux编译使用静态库和动态库
- 容易看懂的才是好代码
- [Practical.Vim(2012.9)].Drew.Neil.Tip10学习摘要
- MediaPlayer 生命周期详解
- hdu 4046 Panda (线段树,单点更新,区间求和)
- Binary Tree Maximum Path Sum
- hihocoder 1156 彩色的树
- 移位运算符:>>,<<,>>>