#P1849. [USACO12MAR] Tractor S

    ID: 802 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>字符串图论贪心2012USACO枚举,暴力

[USACO12MAR] Tractor S

Description

After a long day of work, Farmer John completely forgot that his tractor was still in the middle of the field. His cows, who love to play pranks on him, dropped nn hay bales at various positions in the field. This means John must move some hay bales out of the way before he can drive the tractor out.

Both the tractor and the hay bales are treated as points on a two-dimensional plane with integer coordinates. No hay bale shares the same coordinates as the tractor’s initial position. John can drive the tractor only along the coordinate axes for some number of units. For example, he can first move north by 22 units and then east by 33 units, and so on. The tractor cannot move onto a point occupied by a hay bale.

Please help John compute the minimum number of hay bales that must be moved so that he can drive the tractor back to the origin.

Input Format

The first line contains three space-separated integers, giving the number of hay bales nn and the tractor’s starting coordinates (x0,y0)(x_0, y_0).

Lines 22 through (n+1)(n+1): each line contains two space-separated integers. On line (i+1)(i + 1), the integers xi,yix_i, y_i give the coordinates of the ii-th hay bale (xi,yi)(x_i, y_i).

Output Format

Output a single integer on one line: the minimum number of hay bales that must be moved so John can drive the tractor back to the origin.

7 6 3 
6 2 
5 2 
4 3 
2 1 
7 3 
5 4 
6 4 
1 

Hint

For 100%100\% of the testdata, it is guaranteed that 1n5×1041 \leq n \leq 5 \times 10^4, 1xi,yi1031 \leq x_i, y_i \leq 10^3.

Translated by ChatGPT 5