Challenge Overview
Problem statement
There is an unknown polygon drawn on a 2-dimensional plane. It is not necessarily convex, it is rather not convex in majority of test cases. Your task is to estimate its shape as precisely as possible. Problem specification Initially you have only the following information about the polygon:- Both X and Y coordinates of each vertex are between 0 and 9,999, inclusive.
- No two vertices coincide.
- No three vertices are located on the same straight line.
int[] of 2*M elements where elements 0 and 1 are X and Y coordinates of vertex 0, elements 2 and 3 are the X, Y coordinates of vertex 1, ..., elements 2*M-2 and 2*M-1 are the X, Y coordinates of vertex M-1. Here M is the number of vertices in your estimate of the polygon.
In order to make requests, you can call a static library method sendRequest in class RayCaster (as described above). If you send an incorrect request, the return value will be a double[] containing a single element equal to 0.
Test case generation
Each test case is generated as follows:
# random(L, R) generates a real value uniformly, at random, between L and R
a := random(0.0, 1.0)
D := 5.0 + 45.0 * a * a
P := random(10.0, 100.0)
# randomInt(L, R) generates an integer value uniformly, at random, between L and R, inclusive
# number of polygon's vertices
N := randomInt(10, 100)
# coordinates, in no particular order
for i = 0, 1, ..., N-1:
X[i] = randomInt(0, 9999)
Y[i] = randomInt(0, 9999)
# regenerate if something is bad
while (X[i], Y[i]) coincides with (X[j], Y[j]), j < i, or
(X[i], Y[i]), (X[j], Y[j]) and (X[k], Y[k]), k < j < i,
lie on the same straight line:
X[i] = randomInt(0, 9999)
Y[i] = randomInt(0, 9999)
# generate a proper order
Assume that points go in order 0, 1, 2, ..., N-1.
for i = 0, 1, ..., N-3:
for j = i+2, i+3, ..., N-1:
if (i == 0) and (j == N-1):
break
A := segment between (X[i], Y[i]) and (X[i+1], Y[i+1])
B := segment between (X[j], Y[j]) and (X[(j+1)%N], Y[(j+1)%N])
if A and B intersect:
# Remove (i)-(i+1) and (j)-(j+1) sides.
# Add (i)-(j) and (i+1)-(j+1) sides.
# This reverses the order of the points from i+1 to j.
Reorder points as 0, 1, ..., i, j, j-1, ..., i+1, j+1, j+2, ..., N-1.
Restart the "for i" cycle above from scratch.
# once done, 0, 1, .., N-1 order defines a valid polygon
Tools
A visualizer/offline tester is available. You can check its source code for an exact implementation of test case generation, request handling and scoring. It also allows manual playing.
Legacy definition
Class: PolygonEstimation
String displayTestCase(String s) int[] estimate(double D, double P) RayCaster.double[] sendRequest(int x1, int y1, int x2, int y2)
Notes
- The memory limit is 1024 MB and the time limit is 10 seconds (which includes only time spent in your code).
- There is no explicit code size limit. The implicit source code size limit is around 1 MB (it is not advisable to submit codes of size close to that or larger). Once your code is compiled, the binary size should not exceed 1 MB.
- The compilation time limit is 30 seconds. You can find information about compilers that we use and compilation options here.
- There are 10 example test cases and 100 full submission test cases.
Examples
Example 0
Input
"1"
Legacy example display output
"N = 91 D = 20.61354534858991 P = 45.93229603372773"
Example 1
Input
"2"
Legacy example display output
"N = 21 D = 13.726055904597247 P = 12.305219227908449"
Example 2
Input
"3"
Legacy example display output
"N = 70 D = 35.0351033657376 P = 20.77148561706445"
Example 3
Input
"4"
Legacy example display output
"N = 74 D = 39.184059544374826 P = 25.64704548673069"
Example 4
Input
"5"
Legacy example display output
"N = 99 D = 13.449951930454125 P = 14.373876861986961"
Example 5
Input
"6"
Legacy example display output
"N = 83 D = 48.53947829437732 P = 65.72635643776047"
Example 6
Input
"7"
Legacy example display output
"N = 18 D = 10.937181982134508 P = 37.5250749757682"
Example 7
Input
"8"
Legacy example display output
"N = 62 D = 12.578329816723187 P = 55.54124266699317"
Example 8
Input
"9"
Legacy example display output
"N = 12 D = 25.591029594435025 P = 84.87989527259487"
Example 9
Input
"10"
Legacy example display output
"N = 72 D = 8.348685347691859 P = 11.926436040241912"