ZOJ Problem Set - 2786
When writing game programs, it is often useful to determine when two polygons intersect one another. This is especially useful in arcade games like Asteroids where one polygon could represent a spaceship while another represents a huge, unyielding chunk of space rock.
Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each data set consists of the following components:
1. A line containing a single positive integer m (1 <= m <= 10) indicating the number of polygons to analyze.
For each dataset in the input, output the heading "Data Set #z", where z is 1 for the first dataset, 2 for the second, etc. If this data set contained no intersecting polygons, output the message "no collisions" on its own line. Otherwise, output the list of all pairs of intersecting polygons, one pair per line, each pair formatted with the lowest-numbered polygon first. Output the polygon pairs in ascending order, sorting first by the lowest-numbered polygon in the set and then the second.
Note: The definition of "intersecting" for the purpose of this problem means that two polygons either share an interior region (i.e., they overlap), or they share boundary points (i.e., they touch at a point or along an edge).
2 2 4 0,0 1,0 1,1 0,1 4 2,2 3,2 3,3 2,3 4 3 2,1 1,2 2,3 3 2,1 3,2 2,3 5 2,0 4,2 2,4 5,4 5,0 4 3,3 1,3 1,5 3,5
Data Set #1 no collisions Data Set #2 1 2 1 4 2 4 3 4
Source: South Central USA Regional Programming Contest 2006