这道题怎么做?

fairfox 2002-04-06 09:43:38
别人告诉我说要离散化,可是具体怎么搞呢?
...全文
32 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fairfox 2002-04-07
  • 打赏
  • 举报
回复
谢谢!
intfree 2002-04-06
  • 打赏
  • 举报
回复
usaco上的题,

注意到数据范围
1 <= A, B <= 10,000
1 <= N <= 1000
离散化的意思就是,只考虑N个矩形的顶点,这样横竖都不超过2000个点。
否则的话,横竖就有10000个点。

比如样例,表面上有20*20个点,但实际上,
x轴只需考虑0, 2, 8, 10, 18, 19, 20,分别用x1,x2,...,x7表示
y轴只需考虑0, 2, 8, 18, 19, 20,分别用y1,y2,...,y6表示
这样样例中的输入就可以对映到一个7*6的表。
比如2 2 18 18 2,就对映x2 y2 x5 y4 2

于是,时间复杂度将与A,B的范围无关,只与N有关。


离散化后,做法就很多了。要降低时间复杂度,可以考虑用更好的数据结构。
比如线段树,或二叉堆。都可以将时间复杂度降到O(N^2logN)。
fairfox 2002-04-06
  • 打赏
  • 举报
回复
不好意思,忘记帖题目了:
Shaping Regions
N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.

The coordinate system has its origin (0,0) at the sheet's lower left corner with axes parallel to the sheet's borders.

PROGRAM NAME: rect1
INPUT FORMAT
The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle "on the bottom". Line 1: A, B, and N, space separated (1 <= A,B <= 10,000)
Lines 2-N+1: Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed.


SAMPLE INPUT (file rect1.in)
20 20 3
2 2 18 18 2
0 8 19 19 3
8 0 10 19 4

OUTPUT FORMAT
The output file should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.
SAMPLE OUTPUT (file rect1.out)
1 91
2 84
3 187
4 38


aliceZOOZ 2002-04-06
  • 打赏
  • 举报
回复
什么题目嘛

33,009

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧