由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问两个算法题, 没什么头绪
相关主题
问一到算法题简单的perl问题
python大牛请进有问题求教[合集] google interview question
有谁读过Design Patterns Explained: A New Perspective on Obj (转载)请问那里可以找到interval tree的 C code (linux)?
What is wrong with the constructor (or the code)?问个算法的问题
[c++]distinct default parameter value in inherited class请教一个快速图像配准的问题
有熟悉cython的大牛吗?Workflow design请教
问个面试题目后端为什么不用Java
[合集] 这个问题怎么做好?(word sqaure)Java GC question
相关话题的讨论汇总
话题: bj话题: interval话题: ci话题: sub话题: weight
进入Programming版参与讨论
1 (共1页)
H***e
发帖数: 476
1
有一点类似。 据说1是经典题?
1. deck of cards
put them randomly on the table.
two cards can only overlap with rectangle area.(cards must be Vertical/
horizontal to the edge of the table)
find the total area covered by those cards?
2. Given are a set of intervals S = {I1,I2.....In}, each interval have
different positive weight (weight is independent to the interval, there may
be the case that a long interval has a low weight but a short interval has
high weight).
Purpose: Find out a subset of S, say Sub, such that for every interval in S,
there is an interval I in Sub such that they are somehow overlap.
Requirement: the total weight of Sub is minimum.
就是说,找到一部分的interval,使得S内的所有interval和他们(中的某一个interval
)都有交集,并且要求最小的weight
l******u
发帖数: 1174
2
#1: Here is my idea:
Divide the non-covered area into non-overlapping rectangles, say:
L = {B1, B2, ..., Bn}
The total covered area would be total area of the table minus the sum of B1,
B2, ..., Bn. When there is no card on the table, L = {Table}, i.e., the
only rectangle is the table itself.
Drop the cards one by one. For each card Ci, there are several scenarios
where it can relate to each rectangle, Bj:
1. The card Ci does not touch Bj.
==> ignore it.
2. The card Ci contains Bj properly
==> remove Bj from L.
3. The card Ci has 1 corner in Bj
=> Bj will be decomposed into 4 smaller rectangles, 1 of which would be
covered by Ci, the rest 3 will replace Bj in L. Illustrated as follows:
+------------########
| ########
| 1 ##card##
| ########
+------------########
| | |
| | |
| | |
| 2 | 3 |
| | |
| | |
+-------------------+
4. The card Ci has 2 corners in Bj
=> Bj will be decomposed into 6 smaller rectangles, 1 of which would be
covered by Ci, the rest 5 will replace Bj in L. Illustrated as follows:
+------------+------+
| 1 | 2 |
| | |
+------------########
| ########
| 3 ##card##
| ########
+------------########
| | |
| 4 | 5 |
+------------+------+
5. The card Ci has 4 corners in Bj
=> Bj will be decomposed into 9 smaller rectangles, 1 of which would be
covered by Ci, the rest 8 will replace Bj in L.
The key function would be to divide a rectangle by 1 point, or 2 points, or
4 points and find the smaller rectangles not covered. Should be
straightforward.

may

【在 H***e 的大作中提到】
: 有一点类似。 据说1是经典题?
: 1. deck of cards
: put them randomly on the table.
: two cards can only overlap with rectangle area.(cards must be Vertical/
: horizontal to the edge of the table)
: find the total area covered by those cards?
: 2. Given are a set of intervals S = {I1,I2.....In}, each interval have
: different positive weight (weight is independent to the interval, there may
: be the case that a long interval has a low weight but a short interval has
: high weight).

z****c
发帖数: 602
3
One idea to solve 1:
Add horizontal intervals and vertical intervals into two interval trees. (
nlogn)
Add the top edge and bottom edge coordinate of cards into an array, sort it.
then you have 2n coodinates and 2n-1 intervals.(nlogn)
Do the same to left and right edge. (nlogn)
All horizontal interval and vertical interval will divide plane into (2n-1)(
2n-1) sub regions.
for each sub region, query two interval trees and find intersection in the
results. You can use a map to find the intersection, which is a O(1) time.
Total time is O(n^2*logn)
i***h
发帖数: 12655
4
第二题是图论题?
每个线段是图上顶点, 带权重.
有重叠的两个线段间有边相连.
然后求顶点的子集.
没想好怎么弄
i***h
发帖数: 12655
5
第一题好象先对牌X-Y排序,
然后从左到右扫描一遍
O(n)
1 (共1页)
进入Programming版参与讨论
相关主题
Java GC question[c++]distinct default parameter value in inherited class
请问大家一个图形的问题:有熟悉cython的大牛吗?
[合集] 问个算法问题问个面试题目
内存泄露了吗?[合集] 这个问题怎么做好?(word sqaure)
问一到算法题简单的perl问题
python大牛请进有问题求教[合集] google interview question
有谁读过Design Patterns Explained: A New Perspective on Obj (转载)请问那里可以找到interval tree的 C code (linux)?
What is wrong with the constructor (or the code)?问个算法的问题
相关话题的讨论汇总
话题: bj话题: interval话题: ci话题: sub话题: weight