A. Cards

Codeforces
IDCF10106A
Time2000ms
Memory64MB
Difficulty
English · Original
Formal · Original
Omar has a deck of cards. Every card has a unique integer number written on it. He says that his cards are numbered starting from 1, and if a card with number N exists, then a card with number N + 1 exists. Yes he may have an infinite sequence ! Yesterday when he went to school, his little brother Samir played with his cards by sorting them into two boxes according to the numbers written on them by repeating the following two steps: First box : 1, 3, 4, 5, 7, ... Second box : 2, 6, 8, 10, 14, ... Omar came back home and he asked Samir for the card with number Q written on it. Help Samir to find out in which box he can find the required card. Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases . T lines follow, each describing a test case consisting of a single integer Q (1 ≤ Q ≤ 1018) For every test case print "First Box" if the card is in the first box or "Second Box" otherwise. ## Input Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases . T lines follow, each describing a test case consisting of a single integer Q (1 ≤ Q ≤ 1018) ## Output For every test case print "First Box" if the card is in the first box or "Second Box" otherwise. [samples]
**Definitions** Let $ H, W \in \mathbb{R} $ be the height and width of the larger map. Let $ P_1 = (x_1, y_1), P_2 = (x_2, y_2), P_3 = (x_3, y_3), P_4 = (x_4, y_4) $ be the coordinates of the four corners of the smaller map on the larger map, in order: lower left, lower right, upper right, upper left. **Constraints** 1. $ 10 \leq H, W \leq 1000 $ 2. $ 0 < x_i < W $, $ 0 < y_i < H $ for $ i \in \{1,2,3,4\} $ 3. The quadrilateral $ P_1P_2P_3P_4 $ is a rectangle with the same dimensions and orientation as the smaller map. 4. The scale ratio $ r \in [0.01, 0.99] $ satisfies $ \frac{\|P_2 - P_1\|}{W} = \frac{\|P_4 - P_1\|}{H} = r $ **Objective** Find a point $ (x_p, y_p) \in \mathbb{R}^2 $ such that its normalized position relative to the larger map equals its position relative to the smaller map’s local coordinate system. That is, if the smaller map is scaled and placed such that its corners coincide with $ P_1, P_2, P_3, P_4 $, then $ (x_p, y_p) $ is the fixed point of the affine transformation mapping the unit rectangle $ [0,1] \times [0,1] $ to the rectangle $ P_1P_2P_3P_4 $, and also corresponds to the same physical location in both maps. This point satisfies: $$ (x_p, y_p) = P_1 + x_p \cdot (P_2 - P_1) + y_p \cdot (P_4 - P_1) $$ with the constraint that $ (x_p, y_p) $ lies in $ [0,1] \times [0,1] $, and is invariant under the transformation from the unit square to the target rectangle. Solve for $ (x_p, y_p) $ such that: $$ x_p = \frac{(x_2 - x_1) x_p + (x_4 - x_1) y_p + x_1}{W} \cdot W \\ y_p = \frac{(y_2 - y_1) x_p + (y_4 - y_1) y_p + y_1}{H} \cdot H $$ Rewriting as a linear system: $$ x_p = x_1 + x_p (x_2 - x_1) + y_p (x_4 - x_1) \\ y_p = y_1 + x_p (y_2 - y_1) + y_p (y_4 - y_1) $$ Rearranged: $$ x_p (1 - (x_2 - x_1)) - y_p (x_4 - x_1) = x_1 \\ - x_p (y_2 - y_1) + y_p (1 - (y_4 - y_1)) = y_1 $$ But more cleanly: Define vectorially: Let $ \vec{u} = (x_2 - x_1, y_2 - y_1) $, $ \vec{v} = (x_4 - x_1, y_4 - y_1) $ Then the point $ (x_p, y_p) $ in the unit square maps to: $$ T(x_p, y_p) = P_1 + x_p \vec{u} + y_p \vec{v} $$ We seek $ (x_p, y_p) $ such that: $$ (x_p, y_p) = T(x_p, y_p) $$ So: $$ x_p = x_1 + x_p (x_2 - x_1) + y_p (x_4 - x_1) \\ y_p = y_1 + x_p (y_2 - y_1) + y_p (y_4 - y_1) $$ Thus, the system: $$ x_p (1 - (x_2 - x_1)) - y_p (x_4 - x_1) = x_1 \\ x_p (y_1 - y_2) + y_p (1 - (y_4 - y_1)) = y_1 $$ Let: $ a = 1 - (x_2 - x_1) $, $ b = -(x_4 - x_1) $, $ c = y_1 - y_2 $, $ d = 1 - (y_4 - y_1) $ Then: $$ a x_p + b y_p = x_1 \\ c x_p + d y_p = y_1 $$ Solve this 2×2 linear system for $ (x_p, y_p) $. **Final Objective** Find $ (x_p, y_p) $ satisfying: $$ \begin{cases} x_p (1 - (x_2 - x_1)) + y_p (-(x_4 - x_1)) = x_1 \\ x_p (y_1 - y_2) + y_p (1 - (y_4 - y_1)) = y_1 \end{cases} $$
API Response (JSON)
{
  "problem": {
    "name": "A. Cards",
    "description": {
      "content": "Omar has a deck of cards. Every card has a unique integer number written on it. He says that his cards are numbered starting from 1, and if a card with number N exists, then a card with number N + 1 e",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10106A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Omar has a deck of cards. Every card has a unique integer number written on it. He says that his cards are numbered starting from 1, and if a card with number N exists, then a card with number N + 1 e...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ H, W \\in \\mathbb{R} $ be the height and width of the larger map.  \nLet $ P_1 = (x_1, y_1), P_2 = (x_2, y_2), P_3 = (x_3, y_3), P_4 = (x_4, y_4) $ be the coordinates of the four...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments