Build a Wall!
Time limit2.5sMemory limit1024 MB
Given a convex N-gon and query points, find for each point the triangulation that maximizes how many diagonals must be crossed to reach it from outside.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Geometry, Tree
- Solved
- No attempts yet
Problem
After the new leader Junwon takes power in X Kingdom, he decides to build walls inside the country. X Kingdom already has a convex -gon of walls around its outer boundary. Even so, Junwon wants to add more walls inside the country to protect the home he plans to build there.
New walls can only be built as segments joining two vertices of the outer -gon. Two walls cannot cross at any point other than their endpoints. Junwon plans to build additional walls. He has also chosen candidate sites for his home. For each candidate site, Junwon wants to solve the following question.
Place the walls so that the minimum number of walls that must be crossed to reach this site from outside X Kingdom is as large as possible. Find the maximum possible value of that minimum.
Find the answer for each candidate site.
Input
The first line contains a positive integer ().
The next lines contain the coordinates of the vertices of the outer wall in counterclockwise order. The outer walls are the segments from to , from to , and so on, until to , forming a convex -gon.
The next line contains the number of candidate sites ().
The next lines contain the coordinates of each candidate site. Each site is inside X Kingdom and does not lie on the line through any two vertices.
All coordinates have at most six digits after the decimal point, and their absolute values are at most . The answer does not change if any coordinate changes by up to .
Output
For each of the candidate sites, print the maximum possible minimum number of walls that must be crossed to reach it from outside, one per line, in input order.