CF818C.Sofa Thief
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that x__a < x__b, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that y__a < y__b, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cnt__l sofas to the left of Grandpa Maks's sofa, cnt__r — to the right, cnt__t — to the top and cnt__b — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
DecoForces 平台的又一轮比赛即将开始!Maks 爷爷本想参加,但有人偷走了他心爱的沙发!在这种重大损失下,人又怎能发挥出色呢?
幸运的是,小偷给 Maks 爷爷留下了一张便条。这张便条将 Maks 爷爷引到了沙发仓库。然而,由于所有沙发看起来都一模一样,他完全无法分辨哪一个是自己的!
仓库被建模为一个 n×m 的矩阵。每张沙发占据两个在某一边上相邻的格子(即上下或左右相邻)。任意一个格子最多被一张沙发覆盖。可能存在空着的格子。
若存在两个格子 a 和 b,使得 xa<xb,且 a 被沙发 A 占据、b 被沙发 B 占据,则称沙发 A 位于沙发 B 的左侧;
若存在两个格子 a 和 b,使得 ya<yb,且 a 被沙发 A 占据、b 被沙发 B 占据,则称沙发 A 位于沙发 B 的上方;
同理可定义“右侧”和“下方”。
注意:在上述所有定义中,均要求 A=B。此外,某张沙发 A 可能既在另一张沙发 B 的上方,又在其下方;左右关系亦同理。
便条中还指出:在 Maks 爷爷的沙发左侧有 cntl 张沙发,右侧有 cntr 张,上方有 cntt 张,下方有 cntb 张。
Maks 爷爷请你帮他找出自己的沙发。题目保证满足这些条件的沙发至多只有一张。
请输出 Maks 爷爷的沙发的编号(即输入中沙发的序号,从 1 开始);若不存在满足全部条件的沙发,则输出 −1。
输入格式
The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.
Next d lines contains four integer numbers _x_1, _y_1, _x_2, _y_2 (1 ≤ _x_1, _x_2 ≤ n, 1 ≤ _y_1, _y_2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (_x_1, _y_1) and (_x_2, _y_2) have common side, (_x_1, _y_1) ≠ (_x_2, _y_2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cnt__l, cnt__r, cnt__t, cnt__b (0 ≤ cnt__l, cnt__r, cnt__t, cnt__b ≤ d - 1).
第一行包含一个整数 d(1≤d≤105)——仓库中沙发的数量。
第二行包含两个整数 n、m(1≤n,m≤105)——仓库的尺寸。
接下来的 d 行,每行包含四个整数 x1,y1,x2,y2(1≤x1,x2≤n,1≤y1,y2≤m)——第 i 个沙发的坐标。保证格子 (x1,y1) 与 (x2,y2) 有公共边,(x1,y1)=(x2,y2),且任意格子至多被一个沙发覆盖。
最后一行包含四个整数 cnt_l, cnt_r, cnt_t, cnt_b(0≤cnt_l,cnt_r,cnt_t,cnt_b≤d−1)。
输出格式
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
输出满足所有条件的沙发编号。沙发按输入中给出的顺序编号为 1 至 d。若不存在满足条件的沙发,则输出 −1。
输入输出样例
输入#1
2 3 2 3 1 3 2 1 2 2 2 1 0 0 1
输出#1
1
输入#2
3 10 10 1 2 1 1 5 5 6 5 6 4 5 4 2 1 2 0
输出#2
2
输入#3
2 2 2 2 1 1 1 1 2 2 2 1 0 0 0
输出#3
-1
说明/提示
Let's consider the second example.
- The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
- The second sofa has cnt__l = 2, cnt__r = 1, cnt__t = 2 and cnt__b = 0.
- The third sofa has cnt__l = 2, cnt__r = 1, cnt__t = 1 and cnt__b = 1.
So the second one corresponds to the given conditions.
In the third example
- The first sofa has cnt__l = 1, cnt__r = 1, cnt__t = 0 and cnt__b = 1.
- The second sofa has cnt__l = 1, cnt__r = 1, cnt__t = 1 and cnt__b = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
我们考虑第二个例子。
- 第一个沙发左侧有 0 个沙发,右侧有 2 个沙发(坐标 (1, 1) 在 (5, 5) 和 (5, 4) 的左侧),上方有 0 个沙发,下方有 2 个沙发(第 2 和第 3 个沙发均在其下方)。
- 第二个沙发有 cntl = 2、cntr = 1、cntt = 2 和 cntb = 0。
- 第三个沙发有 cntl = 2、cntr = 1、cntt = 1 和 cntb = 1。
因此,第二个沙发满足给定的条件。
在第三个例子中:
- 第一个沙发有 cntl = 1、cntr = 1、cntt = 0 和 cntb = 1。
- 第二个沙发有 cntl = 1、cntr = 1、cntt = 1 和 cntb = 0。
而没有任何一个沙发满足集合 (1, 0, 0, 0),因此答案为 −1。
输入解题思路,AI测评打分。不知道怎么写?