ICPC 2016 - H. Polygonal Puzzle
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2016/H-polygonal-puzzle. Edit
competitive_programming/icpc/2016/H-polygonal-puzzle/solution.tex to update the written solution and
competitive_programming/icpc/2016/H-polygonal-puzzle/solution.cpp to update the implementation.
The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.
Problem Statement
Copied statement text kept beside the solution archive for direct reference.
Problem H
Polygonal Puzzle
Time limit: 20 seconds
During last year’s ACM ICPC World Finals in Marrakesh, one of the judges bought a pretty wooden
puzzle depicting a camel and palm trees (see Figure H.1). Unlike traditional jigsaw puzzles, which are
usually created by cutting up an existing rectangular picture, all the pieces of this puzzle have been cut
and painted separately. As a result, adjacent pieces often do not share common picture elements or
colors. Moreover, the resulting picture itself is irregularly shaped. Given these properties, the shape of
individual pieces is often the only possible way to tell where each piece should be placed.
Figure H.1: The judge’s wooden puzzle.
The judge has been wondering ever since last year whether it is possible to write a program to solve this
puzzle. An important part of such a program is a method to evaluate how well two puzzle pieces “match”
each other. The better the match, the more likely it is that those pieces are adjacent in the puzzle.
Pieces are modeled as simple polygons. Your task is to find a placement of two given polygons such that
their interiors do not overlap but the polygons touch with their boundaries and the length of the common
boundary is maximized. For this placement, polygons can be translated and rotated, but not reflected or
resized. Figure H.2 illustrates the optimal placement for Sample Input 1.
Input
The input contains the description of two polygons, one after the other. Each polygon description starts
with a line containing an integer n (3 ≤ n ≤ 50) denoting the number of vertices of the polygon. This
is followed by n lines, each containing two integer coordinates x, y of a polygon vertex (|x|, |y| ≤ 100).
The vertices of each polygon are given in clockwise order, and no three consecutive vertices are collinear.
The input data is chosen so that even if the vertices were moved by a distance of up to 10−7 , the answer
would not increase by more than 10−4 .
Figure H.2: Sample Input 1 and its optimal placement.
Output
Display the maximum possible length of the common boundary of these polygons when they are opti-
mally placed. Your answer should have an absolute or relative error of less than 10−3 .
Sample Input 1 Sample Output 1
8 30.142135624
0 0
0 10
10 10
15 15
24 6
24 10
30 10
30 0
7
-5 0
-5 10
10 10
15 5
20 10
35 10
35 0
Sample Input 2 Sample Output 2
3 50
1 0
0 30
40 0
3
1 0
0 30
40 0
Editorial
Rendered from the copied solution.tex file. The original TeX source remains
available below.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
Exact copied C++ implementation from solution.cpp.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files
Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2016\\H. Polygonal Puzzle}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Problem Summary}
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
\section*{Key Observations}
\begin{itemize}[leftmargin=*]
\item Write the structural observations that make the problem tractable.
\item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
\item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}
\section*{Algorithm}
\begin{enumerate}[leftmargin=*]
\item Describe the data structures and the state maintained by the algorithm.
\item Explain the processing order and why it is sufficient.
\item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}
\section*{Correctness Proof}
We prove that the algorithm returns the correct answer.
\paragraph{Lemma 1.}
State the first key claim.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Lemma 2.}
State the next claim if needed.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.
\paragraph{Proof.}
Combine the lemmas and finish the argument.
\section*{Complexity Analysis}
State the running time and memory usage in terms of the input size.
\section*{Implementation Notes}
\begin{itemize}[leftmargin=*]
\item Mention any non-obvious implementation detail that is easy to get wrong.
\item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}
\end{document}
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}