Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2018 /finals /citylights.html
wjomlex's picture
2018 Problems
ab396f0 verified
<p>
Dahlia is taking a roadtrip across all of Canada! Along the way, she's spending a night in one of the country's hallmark cities, Toronto.
</p>
<p>
Toronto's nighttime skyline can be represented as a 2D plane, with the ground forming a horizontal line with y-coordinate 0.
There are <strong>W</strong> building windows, with the <em>i</em>th one at coordinates (<strong>XW<sub>i</sub></strong>, <strong>YW<sub>i</sub></strong>).
There are also <strong>S</strong> visible stars, with the <em>i</em>th one at coordinates (<strong>XS<sub>i</sub></strong>, <strong>YS<sub>i</sub></strong>).
It's guaranteed that all <strong>W</strong> + <strong>S</strong> of these points are distinct, and that no star is directly below a window (having the same x-coordinate but a smaller y-coordinate).
</p>
<p>
At night, it's impossible to see any given window unless there's light coming from it. On any given night, each window is independently either lit up or not with equal probability.
As such, there are 2<sup><strong>W</strong></sup> equally-likely subsets of windows which might be visible. Dahlia finds herself looking at Toronto's skyline on one such random night.
</p>
<p>
Dahlia knows that Toronto consists of 0 or more buildings, each of which covers a rectangular portion of the sky with some bottom-left corner (<strong>x<sub>1</sub></strong>, 0)
and some top-right corner (<strong>x<sub>2</sub></strong>, <strong>h</strong>),
for some real values of <strong>x<sub>1</sub></strong>, <strong>x<sub>2</sub></strong>, and <strong>h</strong>
(such that <strong>x<sub>1</sub></strong> &lt; <strong>x<sub>2</sub></strong> and <strong>h</strong> &gt; 0).
The buildings might overlap with one another. Based on Dahlia's view of the stars and lit-up windows, she can infer some things about the set of buildings present.
In particular, for each lit-up window <em>i</em>, Dahlia realizes that there must be at least one building whose rectangle inclusively covers the point
(<strong>XW<sub>i</sub></strong>, <strong>YW<sub>i</sub></strong>). Furthermore, for each star <em>i</em>,
Dahlia realizes that there must be no buildings whose rectangles inclusively cover the point (<strong>XS<sub>i</sub></strong>, <strong>YS<sub>i</sub></strong>).
</p>
<p>
Dahlia is going to assume that Toronto consists of as few buildings as possible which are consistent with her observations on that night.
What's the expected number of buildings which she'll assume exist?
In order to avoid floating-point arithmetic and large integers, output this expected number multiplied by 2<sup><strong>W</strong></sup> (which is guaranteed to result in an integer) and then taken modulo 1,000,000,007.
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of skylines.
For each skyline, there is first a line containing the space-separated integers <strong>W</strong> and <strong>S</strong>.
Then, <strong>W</strong> lines follow, the <em>i</em>th of which contains the space-separated integers <strong>XW<sub>i</sub></strong> and <strong>YW<sub>i</sub></strong>.
Then, <strong>S</strong> lines follow, the <em>i</em>th of which contains the space-separated integers <strong>XS<sub>i</sub></strong> and <strong>YS<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th universe, output a line containing "Case #<em>i</em>: " the expected number of buildings which Dahlia will assume exist, multiplied by 2<sup><strong>W</strong></sup> and then taken modulo 1,000,000,007.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 150 <br />
1 &le; <strong>W</strong> &le; 80 <br />
1 &le; <strong>S</strong> &le; 50 <br />
1 &le; <strong>XW<sub>i</sub></strong>, <strong>YW<sub>i</sub></strong>, <strong>XS<sub>i</sub></strong>, <strong>YS<sub>i</sub></strong> &le; 1,000,000,000 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, there's a 50% chance that the single window will be visible, in which case Dahlia will assume that Toronto has 1 building.
There's also a 50% chance that it won't be visible, in which case she'll assume that there are 0 buildings. As such, the expected number of buildings which she'll assume exist is (1 + 0) / 2 = 1/2.
This should then be multiplied by 2<sup>1</sup> and taken modulo 1,000,000,007 to produce a final answer of 1.
</p>
<p>
In the second case, however many windows are visible, Dahlia will assume Toronto has that many buildings. For example, if both windows are visible, then there must be at least 2 buildings, as a single building can't account for both windows without also covering the single visible star. This results in a final answer of ((0 + 1 + 1 + 2) / 4 * 2<sup>2</sup>) modulo 1,000,000,007 = 4.
</p>
<p>
In the third case, the final answer is ((0 + 1 + 1 + 1 + 1 + 1 + 2 + 2) / 8 * 2<sup>3</sup>) modulo 1,000,000,007 = 9.
</p>