monotone_matrix_search() and sorted_matrix_search() are techniques that deal with the problem of efficiently finding largest entries in matrices with certain structural properties. Many concrete problems can be modelled as matrix search problems, and for some of them we provide explicit solutions that allow you to solve them without knowing about the matrix search technique. Examples are, the computation of all furthest neighbors for the vertices of a convex polygon, maximal k-gons inscribed into a planar point set, and computing rectangular p-centers.

monotone_matrix_search() 和 sorted_matrix_search()处理的问题是在一定结构属性的矩阵中高效寻找最大入口。很多具体的问题可以建模为矩阵搜索问题,有些问题我们可以在你不知道矩阵搜索技术的情况下提供显式解决问题的方法。这方面的例子有:计算一个凸多边形的顶点集的所有最远邻居,一个平面点集的内接最大k边形(k-gon)和求一个矩形p心。

Example

本例我们建立一个随机的向量 a=(ai)i=1,…,5 (由0-99中均匀分布产生)并创建一个笛卡尔矩阵M,矩阵中包含所有ai+aj,i,j∈{1,…,5},如果a排序,则M也排序。则我们可以使用 sorted_matrix_search() 来计算M中a的最大入口的上界。

In the following program we build a random vector a=(ai)i=1,…,5 (elements drawn uniformly from {0,…,99}) and construct a Cartesian matrix M containing as elements all sums ai+aj,i,j∈{1,…,5}. If a is sorted, M is sorted as well. So we can apply sorted_matrix_search() to compute the upper bound for the maximal entry of a in M.

File Matrix_search/sorted_matrix_search.cpp

#include <CGAL/Random.h>
#include <CGAL/Cartesian_matrix.h>
#include <CGAL/sorted_matrix_search.h>
#include <vector>
#include <algorithm>
#include <iterator>
#include <boost/functional.hpp>
 
typedef int Value;
typedef std::vector<Value> Vector;
typedef Vector::iterator Value_iterator;
typedef std::vector<Vector> Vector_cont;
typedef CGAL::Cartesian_matrix<std::plus<int>,
Value_iterator,
Value_iterator> Matrix;
 
int main()
{
// set of vectors the matrices are build from:
Vector_cont vectors;
 
// generate a random vector and sort it:
Vector a;
const int n = 5;
for (int i = 0; i < n; ++i)
a.push_back(CGAL::get_default_random()(100));
std::sort(a.begin(), a.end());
std::cout << "a = ( ";
std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout," "));
std::cout << ")\n";
 
// build a Cartesian matrix from a:
Matrix M(a.begin(), a.end(), a.begin(), a.end());
 
// search for an upper bound for max(a):
Value bound = a[n-1];
Value upper_bound =
&M, &M + 1,
CGAL::sorted_matrix_search_traits_adaptor(
boost::bind2nd(std::greater_equal<Value>(), bound), M));
std::cout << "Upper bound for " << bound << " is "
<< upper_bound << "." << std::endl;
 
return 0;
}

Monotone and Sorted Matrix Search ( Arithmetic and Algebra) CGAL 4.13 -User Manual的更多相关文章

  1. Algebraic Foundations ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    理解: 本节主要介绍CGAL的代数结构和概念之间的互操作.与传统数论不同,CGAL的代数结构关注于实数轴的“可嵌入”特征.它没有将所有传统数的集合映射到自己的代数结构概念中,避免使用“数的类型”这一术 ...

  2. Modular Arithmetic ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Introduction Modular arithmetic is a fundamental tool in modern algebra systems. In conjunction wi ...

  3. Linear and Quadratic Programming Solver ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Which Programs can be Solved? This package lets you solve convex quadratic programs of the general ...

  4. Algebraic Kernel ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Introduction Real solving of polynomials is a fundamental problem with a wide application range. T ...

  5. Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...

  6. 【LeetCode】378. Kth Smallest Element in a Sorted Matrix 解题报告(Python)

    [LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...

  7. sorted matrix - search & find-k-th

    sorted matrix ( Young Matrix ) search for a given value in the matrix: 1) starting from upper-right ...

  8. 【leetcode】378. Kth Smallest Element in a Sorted Matrix(TOP k 问题)

    Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kt ...

  9. 378. Kth Smallest Element in a Sorted Matrix(java,优先队列)

    题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the ...

随机推荐

  1. TZOJ 4007 The Siruseri Sports Stadium(区间贪心)

    描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...

  2. python之socket运用之传输大文件

    socket建议最大的传输单元是8192个字符,但是如果超过8192就会出现问题,我们可以用下面的方法处理 客户端代码 import subprocess import socket ip_bind ...

  3. Message: u'The given selector btn dropdown-toggle btn-info is either invalid or does not result in a WebElement

    html代码: <html> <head> <meta http-equiv="content-type" content="text/ht ...

  4. win7系统administrator用户提示没有管理员权限,造装驱动安装错误,软件无法使用

    警告1909.无法创建快捷方式 最近使用windows 7 32位安装软件,好多都失败.出现以上类似错误. 解决方法:在系统盘(C:)右键属性“安全”选项卡--“编辑”,添加“Everyone”设置为 ...

  5. PAT 1073 多选题常见计分法(20)(代码+思路)

    1073 多选题常见计分法(20 分) 批改多选题是比较麻烦的事情,有很多不同的计分方法.有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数:如果考生 ...

  6. Debian use sudo

    刚安装好的Debian默认还没有sudo功能.1.安装sudo# apt-get install sudo2.编辑 /etc/sudoers ,添加如下行# visudoroot ALL=(ALL:A ...

  7. MongoDB复制集搭建(3.4.17版)

    ==版本== mongodb-linux-x86_64-rhel70-3.4.17.tgz ==准备== 3个节点,我这里的IP及hostname分别是: 10.11.2.52 dscn49 10.1 ...

  8. $.post 提示错误: Uncaught SyntaxError: Unexpected token :

    $.post("addRecommond",{"productId":productId,"categoryCode":categoryCo ...

  9. Json和XML解析

    NSXMLParse 关于XML,有两种解析方式,分别是SAX(Simple API for XML,基于事件驱动的解析方式,逐行解析数据,采用协议回调机制)和DOM(Document Object ...

  10. 小程序getUserInfo授权升级更新登录优化

    小程序基础库2.0.7更新小程序组件 <button> 新增 open-type 属性有效值 openSetting,所以说,再也不能愉快的直接调用getUserInfo了.但是不想用官方 ...