Book of programming problems

Contains advanced programming problems for schools, colleges and problem-hungry inidividuals

Move minimal number of matches to obtain a symmetric figure.
Complexity (1-100): 35
N matches on a plane constitute a figure (N≤15). A figure A is symmetric to figure B iff there exists an axis of symmetry such that B can be obtained by flipping A around that axis.

Obviously, each figure can be flipped by moving its matches. Matches cannot be broken, but can be put one on another.

Write a program flipping a figure by moving minimal number of matches. Input data is stored in a file containing N in the first line, then N lines each containing space-separated coordinates of matches ends (x1, y1) - (x2, y2) of figure A. The program should output 1) a number of moved matches and 2) N lines containing coordinates of matches in the symmetric figure B.

Example:
     INPUT.TXT        OUTPUT
3 1
1 0 1 5 9 0 9 5
2 4 5 0 2 4 5 0
5 0 8 4 5 0 8 4

Notes. All coordinates are integer. The program is allowed to run no longer than 1 sec.
Solution:solution.pas
There are no posts in this topic.

Post Reply

Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin