uva-10245-分治

题意:数组二维空间内的点,求最近的俩个点的距离.

根据x排序,求左部分的最近距离,右部分最近距离,然后以中点,当前距离为半径,计算所有的点距离.

#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
#include "stdio.h"
namespace cc
{using std::cout;using std::endl;using std::cin;using std::map;using std::vector;using std::string;using std::sort;using std::priority_queue;using std::greater;using std::vector;using std::swap;using std::stack;using std::bitset;class Node{public:double x;double y;Node() {};Node(double x, double y) :x(x), y(y) {};};constexpr int N = 10000;Node a[N + 1];bool cmp(Node& a, Node& b){return a.x < b.x;}double dist(Node a, Node b){return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));}double minDist(int l, int r){if (l > r) return 40004;int mid = (l + r) / 2;int s = mid, e = mid;double d = std::min(minDist(l, mid - 1), minDist(mid + 1, r));while (s >= l && d > a[mid].x - a[s].x) s--;while (e <= r && d >  a[e].x- a[mid].x) e++;for (int i = s + 1;i < e;i++){for (int j = i + 1;j < e;j++){d = std::min(dist(a[i], a[j]), d);}}return d;}void solve(){double s, e;int n;while (cin >> n && n){for (int i = 0;i < n;i++){cin >> s >> e;Node node(s, e);a[i] = node;}sort(a, a + n, cmp);double d = minDist(0,n-1);if (d >= 10000){cout << "INFINITY" << endl;}else{printf("%.4lf\n",d);}}}};int main()
{#ifndef ONLINE_JUDGEfreopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGEcc::solve();return 0;
}

另外,这个题裸奔也行的

#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
#include "stdio.h"
namespace cc
{using std::cout;using std::endl;using std::cin;using std::map;using std::vector;using std::string;using std::sort;using std::priority_queue;using std::greater;using std::vector;using std::swap;using std::stack;using std::bitset;class Node{public:double x;double y;Node() {};Node(double x, double y) :x(x), y(y) {};};constexpr int N = 10000;Node a[N + 1];bool cmp(Node& a, Node& b){return a.x < b.x;}double dist(Node a, Node b){return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));}double minDist(int l, int r){if (l > r) return 40004;int mid = (l + r) / 2;int s = mid, e = mid;double d = std::min(minDist(l, mid - 1), minDist(mid + 1, r));while (s >= l && d > a[mid].x - a[s].x) s--;while (e <= r && d >  a[e].x- a[mid].x) e++;for (int i = s + 1;i < e;i++){for (int j = i + 1;j < e;j++){d = std::min(dist(a[i], a[j]), d);}}return d;}void solve(){double s, e;int n;while (cin >> n && n){for (int i = 0;i < n;i++){cin >> s >> e;Node node(s, e);a[i] = node;}sort(a, a + n, cmp);double d = 400000;for (int i = 0;i < n;i++){for (int j = i + 1;j < n;j++){d = std::min(dist(a[i],a[j]),d);}}if (d >= 10000){cout << "INFINITY" << endl;}else{printf("%.4lf\n",d);}}}};int main()
{#ifndef ONLINE_JUDGEfreopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGEcc::solve();return 0;
}

posted on 2019-01-12 00:30 好吧,就是菜菜 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10258327.html

uva-10245-分治相关推荐

  1. UVA 10245 The Closest Pair Problem

    最近点对模板题,算法导论P591有具体的证明,我不会实现  - -!,有一个博主写的很好,具体的证明可以见博客:http://blog.csdn.net/zhang20072844/article/d ...

  2. uva 10245 The Closest Pair Problem_枚举

    题意:求任意两点之间的距离的最少一个距离 思路:枚举一下就可以了 #include <iostream> #include<cstdio> #include<cmath& ...

  3. tp5 mysql缓存_tp5.0 SHOW COLUMNS FROM 生成数据表字段缓存

    TP5.0 生成数据表字段缓存 =控制台执行以下命令= 1.生成指定数据库的所有表字段缓存 php think optimize:schema --db databaseName 2.生成指定数据表的 ...

  4. CDQ分治入门 + 例题 Arnooks's Defensive Line [Uva live 5871]

    CDQ分治入门 简介 CDQ分治是一种特别的分治方法,它由CDQ(陈丹琦)神犇于09国家集训队作业中首次提出,因此得名.CDQ分治属于分治的一种.它一般只能处理非强制在线的问题,除此之外这个算法作为某 ...

  5. UVa 12627 Erratic Expansion - 分治

    因为不好复制题目,就出给出链接吧: Vjudge传送门[here] UVa传送门[here] 请仔细看原题上的那幅图,你会发现,在时间t(t > 0),当前的气球构成的一幅图,它是由三个时间为( ...

  6. UVA - 12627 Erratic Expansion(分治)

    题意:根据题中给出的气球的分裂方式,求第K次分裂后,第A行到第B行的红色气球的数量. 思路:观察气球的分裂方式,可以看出,如果把分裂后的气球分成四块,那么右下角全部都是蓝色气球,并且其它三块气球的对应 ...

  7. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  8. 分治算法的设计思想(二分检索、二分归并排序)

    分治策略思想: 将原问题划分或者归结为规模较小的子问题. 递归或迭代求解每一个问题. 将子问题的解综合得到原问题的解. 性质: 子问题与原问题具有相同的性质. 子问题的求解彼此独立. 划分时子问题的规 ...

  9. [搜索]UVa 129 困难的串

    题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...

  10. 【线段树分治 线性基】luoguP3733 [HAOI2017]八纵八横

    不知道为什么bzoj没有HAOI2017 题目描述 Anihc国有n个城市,这n个城市从1~n编号,1号城市为首都.城市间初始时有m条高速公路,每条高速公路都有一个非负整数的经济影响因子,每条高速公路 ...

最新文章

  1. Alibaba Cloud Linux 2.1903 LTS 64位服务器yum源下载404,Alibaba Cloud Linux 2实例中使用docker-ce、epel等YUM源安装软件失败
  2. ipv6改为ipv4
  3. 微生物领域SCIE期刊分析(英美各40本,中国大陆0本)
  4. python 格式化字符串长度_python-格式化字符串
  5. 如何提高用户注册转化与用户激活
  6. 浅谈工业机器人的运动停止
  7. P4201-[NOI2008]设计路线【结论,树形dp】
  8. 笔记本(华硕UL80VT)软件超频setFSB
  9. dp cf 20190614
  10. AGC018F. Two Trees
  11. oracle 模式_oracle专用模式修改为共享模式
  12. 触发器的创建和使用(sql2005)
  13. 【转载】Eclipse:Android开发中如何查看System.out.println的输出内容
  14. 微信公众号开发之微信模板消息推送
  15. C语言实现可视化,运用EasyX实现拼图+文字解谜+迷宫+猜数游戏
  16. excel2007不显示文件名
  17. 一、mysql数据库基本框架
  18. 版权所有者删除链接要求大部分被尊重 谷歌去年共删3.45亿个侵权
  19. 如何实现H5可视化编辑器的实时预览和真机扫码预览功能
  20. 字节跳动的面试分享,为了拿下这个offer鬼知道我经历了什么

热门文章

  1. 企业运维经典面试题汇总(5)
  2. 禁ping也能ping的工具: tcping
  3. 两个必备小本领——恢复设备出厂配置、如何配置web方式登陆交换机
  4. shell脚本——释放缓存
  5. CSS中选择器的优先级 ( ※关于相同属性的覆盖问题 )
  6. main()如果返回0,则代表程序正常退出,返回非零代表程序异常退出。
  7. PlSqlDev中执行INSERT SQL语句包含符号导致数据异常
  8. elasticsearch问题解决之分片副本UNASSIGNED
  9. VLOOKUP函数返回错误值#N/A的两种解决方法
  10. 什么是lambda(函数)?