Submit | All submissions | Best solutions | Back to list |
LEGO - Lego |
It's Christmas morning, and you've got what you wanted: a box of Lego™! (Okay, maybe not, but better than nothing)
Lego is pretty fun to tinker with, and you've decided to build some sort of shape.
(For the sake of this problem, let's say your shape is basically 2-dimensional - it'll be a slab)
But once you pick it up, you discover that you didn't plan it properly, and your wonderful shape just falls apart.
Now, you're planning to build something big, and so you're going to use the computer to help you.
Write a program, that given the layout of a Lego design, outputs the number of pieces it would break into if picked up.
(Assume that the bricks bind together perfectly)
The Legos will be built on a x-y coordinate plane, with (0,0) being the bottom left corner.
The blocks are flat on your carpet, so a block will never 'fall down'.
(If you haven't seen a Lego brick before: A Lego brick has grooves on its top that match with notches on the bottom.
If a groove and a notch bind, the bricks will stay together. See the diagram.
A brick will bind with another brick securely even if just a single notch touches another groove.
Input:
The first line contains N (the number of Lego pieces), 1 ≤ N ≤ 100000.
N lines follow, each with 4 integers x1, y1, x2, y2 (0 ≤ x1 < x2 ≤ 2×109, 0 ≤ y1 < y2 ≤ 2×109)
This means that there is a brick with bottom left corner (x1,y1) and top right corner (x2,y2). x denotes the horizontal coordinate and y the vertical coordinate. Two bricks will bind if one's bottom y-coordinate coincides with the other's top y-coordinate and the intersection of the two intervals (the bottom of one and the top of the other) has nonzero length.
No bricks will overlap.
Output:
A single line containing the number of separate pieces that these blocks form.
Sample Input:
4 0 0 2 2 1 2 3 4 2 0 4 2 4 0 6 2
Sample Output:
2
Explanation
Blocks #1,2,3 are joined securely.
However, #4 is just hanging around.
Added by: | Brian Bi |
Date: | 2009-04-10 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Hanson Wang |
hide comments
|
|||||
2022-09-14 14:17:58
DSU ❤️❤️❤️ |
|||||
2021-08-04 23:20:00
I get the error "Missing testcases: 'NoneT" upon submission. What does it mean ? |
|||||
2021-04-27 21:50:21
The question has some problem in submission. It says "Missing testcases: 'NoneT" on submitting any solution |
|||||
2019-03-24 14:29:15
How should we construct the graph? |
|||||
2019-03-15 16:12:00
Dont think too much, try to think of simple solution :D And dont use SPOJ TOOLKIT testacases to debug they have some wrong testcases Last edit: 2019-03-15 16:13:03 |
|||||
2016-12-28 11:02:23 Sajal Sarkar
Did someone solve this question via counting connected component? Last edit: 2016-12-28 11:02:51 |
|||||
2016-08-03 19:01:48 SANYAM JAIN
Finally solved it, took so many wa and tle. |
|||||
2016-08-02 20:55:23
After WA n TLE , got AC ;) |
|||||
2016-08-01 09:54:30 Liquid_Science
AC in a go , but took me a lot of time though! :/ |
|||||
2016-05-28 22:38:29 Shubham Sinha
dsu rocks !! |