Country A recently detected abnormal radiation within Country B. Investigations revealed that Country B is spending billions to develop a new type of weapon—a "Chain Array." However, due to the high level of secrecy surrounding this weapon, Country A's spies cannot even determine the exact location of the Chain Array. Nevertheless, Country A's satellites can still locate the base where the Chain Array is situated. We now know that this base is a convex polygon containing radioactive material along its edges. Research has shown that in the plane where this convex polygon lies, it has the following properties:
- It contains the coordinate origin.
- No two edges are on the same line.
- There are no edges parallel to the $x$-axis or $y$-axis.
- The $x$ and $y$ coordinates of all vertices are integers.
Now, Country A can emit an infinitely large fan-shaped detection wave from a satellite, which intersects the plane of the convex polygon along a straight line. This line is either parallel to the $x$-axis or the $y$-axis. Through reflected signals, we can determine the number of intersection points between this line and the convex polygon, as well as the coordinates of all intersection points (if any).
You are required to write a program that determines this convex polygon by controlling the detection waves emitted by the satellite.
Interaction
This is an interactive problem. Your program must interact with the testing library and must not access any files. The testing library provides three sets of functions for program initialization, interaction with the library, and returning the results. Their usage and functions are as follows:
prog_initializemust be called first and can only be called once to initialize the testing library.- The testing library provides two functions,
ask_xandask_y, as a way to interact with the library. The functionask_x(x0, y1, y2)is used to query the intersection of the line $x=x_0$ with the polygon, andask_y(y0, x1, x2)is used to query the intersection of the line $y=y_0$ with the polygon. The return value of the functions is the number of intersection points. After callingask_x(x0, y1, y2), $y_1$ and $y_2$ are assigned the $y$-coordinates of the intersection points. After callingask_y(y0, x1, x2), $x_1$ and $x_2$ are assigned the $x$-coordinates of the intersection points. If there is only one intersection point, the values of $x_1$ and $x_2$ (or $y_1$ and $y_2$) are the same. If there are no intersection points, the values of $x_1$ and $x_2$ (or $y_1$ and $y_2$) are meaningless. - The final set of functions is used by your program to return the results to the testing library. This includes returning the polygon area
ret_area(s), returning the number of polygon verticesret_n(n), and returning the polygon vertex coordinatesret_vertex(x, y). Note thatret_areamust be called beforeret_n, andret_nmust be called beforeret_vertex. Improper calling sequences will force your program to terminate illegally. You must callret_vertex$n$ times after callingret_nto return the vertices of the polygon. Note that if the result returned byret_nis incorrect, the testing library will immediately terminate your program and will not accept subsequent results. Similarly, if an incorrect result is returned inret_vertex, the testing library will also immediately terminate your program. If all results fromret_vertexare correct, the testing library will terminate your program after you return the last vertex coordinate. - You must return the coordinates of all vertices in counter-clockwise order, but you may start from any vertex.
Implementation Details
For Pascal users, your program should reference the testing library using the following statement:
uses detect_lib;
The function prototypes used by the testing library are:
procedure prog_initialize;
function ask_x(const x0: longint; var y1, y2: double): longint;
function ask_y(const y0: longint; var x1, x2: double): longint;
procedure ret_area(const s: double);
procedure ret_n(const n: longint);
procedure ret_vertex(const x, y: longint);
For C/C++ users, you should create a project, include the file libdetect.o, and add the following line to the beginning of your program:
#include "detect_lib.h"
The function prototypes used by the testing library are:
void prog_initialize();
int ask_x(int x0, double *y1, double *y2);
int ask_y(int y0, double *x1, double *x2);
void ret_area(double s);
void ret_n(int n);
void ret_vertex(int x, int y);
Constraints
The maximum value of $n$ is $200$, and the $x$ and $y$ coordinates are in the range $[-10000, 10000]$.
Scoring
If your program exhibits any of the following, it will receive 0 points: Accessed any file (including temporary files) or terminated itself. Called library functions illegally. * Caused the testing library to exit abnormally.
Otherwise, your score for each test case is calculated as follows: 1 point for a correct number of vertices, 2 points for a correct area, and 2 points for completely correct vertex coordinates, with scores being cumulative. The remaining 5 points will be judged based on the total number of times you call ask_x and ask_y.
Examples
Input 1
(Interactive problem, no input file)
Output 1
(Interactive problem, no output file)