This page is still under construction.

Parts of this page are still being built. What you see may change.

Antialiasing

Time limit4sMemory limit1024 MB

Summary
Given a convex polygon and a pixel, find the fraction of the pixel's area inside the polygon as a reduced fraction.
Level

Medium6 of 10

Topics
Geometry, Implementation, Math
Solved
No attempts yet

Problem

To reduce aliasing effects, computer graphics systems render a polygon by setting the brightness of each pixel in proportion to the area of the pixel inside the polygon. If a pixel is completely inside the polygon, that pixel is set to the brightest intensity. If only half of the pixel is inside the polygon, then the pixel is set halfway between darkest and brightest.

Given a convex polygon and a pixel location, determine the fraction of the pixel's area that is inside the polygon. Each pixel is square, and is indexed by its row and column coordinates rr and cc. If a vertex of the polygon is located at (r,c)(r,c), then the vertex is located at the center of the pixel at row rr and column cc. Rows are numbered from 00 starting from the top row, and columns are numbered from 00 starting from the leftmost column.

Input

The first line of input specifies two integers NN (3≤N≤1003 \leq N \leq 100), which is the number of vertices in the convex polygon, and QQ (1≤Q≤10001 \leq Q \leq 1000), which is the number of queries. The next NN lines each contains two integers rr and cc giving the coordinates of the polygon in counterclockwise order. The next QQ lines each contains two integers rr and cc indicating the coordinates of the pixel we are interested in. It is guaranteed that the area of the polygon is positive. All coordinates satisfy 0≤r≤10000 \leq r \leq 1000 and 0≤c≤10000 \leq c \leq 1000.

Output

For each query, display a line indicating the fraction of the pixel's area inside the polygon. The fraction should be in lowest terms.

Examples2

  1. Example 1

    Input
    4 4
    1 1
    4 1
    4 4
    1 4
    3 3
    10 10
    1 3
    1 4
    
    Expected output
    1/1
    0/1
    1/2
    1/4
    
  2. Example 2

    Input
    3 4
    1 1
    11 11
    1 21
    1 1
    11 11
    21 1
    4 4
    
    Expected output
    1/8
    1/4
    0/1
    1/2