c语言sscanf函数的用法是什么
264
2022-08-30
Weird Advertisement (线段树+扫描线)
2DPlaneLand is a land just like a huge 2D plane. The range of X axis is 0 to 109 and the range ofY axis is also 0 to 109. People built houses only in integer co-ordinates and there is exactly one housein each integer co-ordinate.Now UseAndSmile Soap Company is launching a new soap. That’s why they want to advertisethis product as much as possible. So, they selected n persons for this task. Each person will be givena rectangular region. He will advertise the product to all the houses that lie in his region. Eachrectangular region is identified by 4 integers x1, y1, x2 and y2. That means this person will advertisein all the houses whose x co-ordinate is between x1 and x2 (inclusive) and y co-ordinate is between y1and y2 (inclusive).Now after a while they realized that some houses are being advertised by more than one person.So, they want to find the number of houses that are advertised by at least k persons. Since you areone of the best programmers in the city; they asked you to solve this problem.InputInput starts with an integer T (≤ 13), denoting the number of test cases.Each case starts with a line containing two integers n (1 ≤ n ≤ 30000), k (1 ≤ k ≤ 10). Each of thenext n lines will contain 4 integers x1, y1, x2, y2 (0 ≤ x1, y1, x2, y2 ≤ 109, x1 < x2, y1 < y2) denoting arectangular region for a person.OutputFor each case, print the case number and the total number of houses that are advertised by at least kpeople.Renat Mullakhanov (rem. See of the most talented programmers in the world, passed away on March 11, 2011. This is verysad news for all of us. His team went to ACM ICPC World Finals - 2004, placed 4th and won goldmedals. He really was a great programmer. May he rest in peace. This problem is dedicated to him.Sample Input22 10 0 4 41 1 2 52 20 0 4 41 1 2 5Sample OutputCase 1: 27Case 2: 8
题目大概:
有t组样例,每组样例,给出n个矩形,k。求出,被k个矩形覆盖的点的数量。
思路:
这类题,最简单的题是求矩形面积并,直接求覆盖面积。这个题有些地方不一样。一是求点的数量,那么当k个覆盖的矩形是一条线的话,面积是0,但点的数量不是0。所以我们可以把给的矩形扩大一下,求的点的数量就是求面积。二是求k覆盖的面积。原来用一颗线段树求面积并就行了。这里需要建立k颗线段树,分别求1-k的覆盖面积。除了这两点,这个题和普通的求矩形面积并差不多,都是扫描线,然后去重,枚举矩形的边。计算面积。
代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~