eolymp
bolt
Try our new interface for solving problems
Problems

Post Offices

Post Offices

You are given the location of all post offices on earth, and a set of destinations for various packages that need to be shipped. For each package, you need to find the maximal set of post offices that are suitable as destinations for the package --i.e. the set of post offices must satisfy the following constraints: \begin{itemize} \item The post office that is closest to the final destination must be in the result set. \item All post offices that are at most \textbf{2}\% farther than the closest post office must also be present in the result set. \end{itemize} For the purpose of this problem, the earth is approximated to be a perfectly flat sphere, with the radius \textbf{6381} Km. The distance between two points may be computed using the haversine formula: \textbf{A = sin( (lat1-lat2)/2)^2 + cos(lat1) · cos(lat2) · (sin((long1-long2)/2)^2)}; \textbf{DISTANCE = 6381 · 2 · atan2(sqrt(A), sqrt(1-A))}; (you may use other formulas if you please, but note that the arccosine formula has large rounding errors for small distances, and thus you may get wrong results). \InputFile The input file is a binary file; all numbers written in it are written in little-endian representation. It contains, in this order: \begin{itemize} \item \textbf{4} bytes that represent the number of post offices \textbf{N} -- integer number, no greater than \textbf{3000000} \item For each post office, the input file contains two numbers <\textbf{LAT LONG}> (\textbf{4} bytes each) representing the latitude and longitude (in degrees) of the post office. The numbers are single-precision \textbf{IEEE754} floating point numbers. All latitudes are between -\textbf{90} and \textbf{90} degrees; all longitudes are between \textbf{-180} and \textbf{180} degrees. \item \textbf{4} bytes representing the number of packages \textbf{M} (integer number, no greater than \textbf{500000}) \item For each package, the input file contains two numbers <\textbf{LAT LONG}> (\textbf{4} bytes each) representing the latitude and longitude (in degrees) of the destination. The numbers are single-precision \textbf{IEEE754} floating point numbers. All latitudes are between \textbf{-90} and \textbf{90} degrees; all longitudes are between \textbf{-180} and \textbf{180} degrees. \end{itemize} \OutputFile The output file is also a binary file, containing only \textbf{32}-bit integers written in little-endian representation. For each of the \textbf{M} lines in the input file, it must contain: \begin{itemize} \item One integer --the number \textbf{P} of post offices in the destination set \item \textbf{P} integers -- the indices of the post offices in the destination set, sorted in ascending order (lower indices first). The index of the first post office in the input file is considered to be \textbf{1} (and thus, all indices should be between \textbf{1} and \textbf{N}, inclusively) \end{itemize}
Time limit 1 second
Memory limit 64 MiB
Input example #1
��'��)B���?��)B�?��)B�ݽ?*B""�?DD*B""�?""*BDD�?UU*B""�?DD*B�ݽ?��)B�?��)B���?DD*B���?""*B���?��)B�?33*B""�?""*B���?ww*Bff�?UU*B�?UU*B33�?33*B���?DD*B���?""*B���?*Bff�?DD*B�?*BDD�?33*B""�?��)B���?��)B�?DD*B""�?UU*B�?33*BDD�?33*B""�?*BDD�?*B""�?""*B���?*BDD�?ff*BDD�?��)B""�?ff*BDD�?ww*Bff�?��)B���?DD*B�ݽ?33*B���?33*B���?��)B�?33*BDD�?33*B�ݽ?33*B���?DD*B���?DD*B�?UU*B�?33*B���?DD*B���?��)B�?*B�?��)B�?DD*B���?��)B�?UU*B33�?33*B���?33*BDD�?��)B�?""*B""�?UU*BVU�?DD*BDD�?""*B���?��)B���?33*B�ݽ?���A��`B���AwwYB�;�A�I]B���AwwYBDD�A��_BDD�AZ�aB,��A�laB<��A�`B�A�A��_BDD�A��_B�A�A��_B<��A�`B���A_Bz��A�KaB���A_BR8�A}�`B�?�Ah�]BZ��AaB���A�
_B�?�Ah�]Bz5�A�CaB�O�A��VB�A33aB���A�
_Bz��A�KaB|s�A�daB""�ADD]B���A�`B�A�A��_B�x�A�aBDD�AZ�aB,y�A��_B�+�A�]`B���A&^B;L�A�[`B�+�A�]`B�c�A0�TB��A�YaB��A��_B�c�A0�TB d�A�`B!C�A�`B
W�Auy`B33�ADD`B���AwwaB	��A0V`B:�A��WB d�A�v`B
�A��]B d�A�v`B7��A�`B���A33YB�-�A�^B���A[0_B ��A�_B���AK�]Bt�A�-aB2��A
...
Output example #1
^C'gq pq rq sq 	����F�Y�`�c��7�]o��h!�"�"�"b$v$�%�'�)�)�)�)�)�)�+�,��������$��$��$ѽ
�
��
9d� S�$�������%�-�4�S�����V�n�u�x���1�F�L�W�Y�]�ׂ���+�h�����"�>�P�k�r���1�T�����J�L�m�o�����ڈ����s���‰މ���t������{���2�4�5�7�]�c�K�`�z���ݏޏߏ�� �5�`���a�f���������������4���ѕ��F�z�Ė+�H�֗��%������֚ݚ2�U���h�i�j�l�V�?�ğ)�*�.��� šXO*	$�Y�YZ�ZD\�]�^'c�f�g7i�j8k�m"��К�����������#�������J�W�������������&�����e����� :|	J^	x/z/�/���
...
Source SEERC-2011