Consider the positive quadrant of the xy plane. A colored point is a triple (x,y,c) where x is its x-axis coordinate, y is the y-axis coordinate, and c is an integer representing its color.
This program needs to read a set of N colored points, then take some queries and answer them.
A query is represented by four values, (xx1_1, yy1_1, xx2_2, yy2_2) and is used to get the number of different colors inside the rectangle confined within the two points of given coordinates.
This program will read:
Consider the positive quadrant of the xy plane. A colored point is a triple (x,y,c) where x is its x-axis coordinate, y is the y-axis coordinate, and c is an integer representing its color.
This program needs to read a set of N colored points, then take some queries and answer them.
A query is represented by four values, (x_1, y_1, x_2, y_2) and is used to get the number of different colors inside the rectangle confined within the two points of given coordinates.
This program will read:
Consider the positive quadrant of the xy plane. A colored point is a triple (x,y,c) where x is its x-axis coordinate, y is the y-axis coordinate, and c is an integer representing its color.
This program needs to read a set of N colored points, then take some queries and answer them.
A query is represented by four values, (x1, y1, x2, y2) and is used to get the number of different colors inside the rectangle confined within the two points of given coordinates.
This program will read:
C program: gets a set of colored points on the plane and Count distinct colors within a list of rectangles, for everybounding rectangle says how many different colors are in it
NOTE This code does not perform input-checks. Don't tell me it doesn't. I know. This exercise was not about input-checking. It also doesn't print any messages to the user. This program is to be corrected automatically by my university online platform, so it has to strictly get input from stdin print the output. Also please don't comment on usage of scanf()
and printf()
, I know there are better options but that's not the point. ###NOTE
- This code does not perform input-checks. Don't tell me it doesn't. I know. This exercise was not about input-checking. It also doesn't print any messages to the user. This program is to be tested automatically by my university online platform, so it has to strictly get input from stdin print the output. Also please don't comment on usage of
scanf()
andprintf()
; I know there are better options but that's not the point.
That being said, I feel that complexity-wise, this algorithm isn't very efficient, or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(NM), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do less checksfewer tests.
Here's the code:
C program: gets a set of colored points on the plane and a list of rectangles, for every rectangle says how many different colors are in it
NOTE This code does not perform input-checks. Don't tell me it doesn't. I know. This exercise was not about input-checking. It also doesn't print any messages to the user. This program is to be corrected automatically by my university online platform, so it has to strictly get input from stdin print the output. Also please don't comment on usage of scanf()
and printf()
, I know there are better options but that's not the point.
That being said, I feel that complexity-wise, this algorithm isn't very efficient or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(NM), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do less checks.
Here's the code
Count distinct colors within a bounding rectangle
###NOTE
- This code does not perform input-checks. Don't tell me it doesn't. I know. This exercise was not about input-checking. It also doesn't print any messages to the user. This program is to be tested automatically by my university online platform, so it has to strictly get input from stdin print the output. Also please don't comment on usage of
scanf()
andprintf()
; I know there are better options but that's not the point.
That being said, I feel that complexity-wise, this algorithm isn't very efficient, or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(NM), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do fewer tests.
Here's the code:
That being said, I feel that complexity-wise, this algorithm isn't very efficient or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(N^MNM), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do less checks.
That being said, I feel that complexity-wise, this algorithm isn't very efficient or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(N^M), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do less checks.
That being said, I feel that complexity-wise, this algorithm isn't very efficient or at least could be done better. I haven't done a thorough analysis of it, but the complexity is at least O(NM), which is potentially very very bad. I'm interested in constructive feedback on how I could improve the algorithm to make it faster and do less checks.