benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2014_L / Wire Crossing

Problem

Answer published by the source. Consult the official source to check your work against its answer.

question title

Wire Crossing

question content

## Problem Description Moore’s Law states that the number of transistors on a chip will double every two years. Amazingly, this law has held true for over half a century. Whenever current technology no longer allowed more growth, researchers have come up with new manufacturing technologies to pack circuits even denser. In the near future, this might mean that chips are constructed in three dimensions instead of two. But for this problem, two dimensions will be enough. A problem common to all two-dimensional hardware design (for example chips, graphics cards, motherboards, and so on) is wire placement. Whenever wires are routed on the hardware, it is problematic if they have to cross each other. When a crossing occurs, special gadgets have to be used to allow two electrical wires to pass over each other, and this makes manufacturing more expensive. Our problem is the following: you are given a hardware design with several wires already in place (all of them straight line segments). You are also given the start and end points for a new wire connection to be added. You will have to determine the minimum number of existing wires that have to be crossed in order to connect the start and end points. This connection need not be a straight line. The only requirement is that it cannot cross at a point where two or more wires already meet or intersect. Figure L.1 shows the first sample input. Eight existing wires form five squares. The start and end points of the new connection are in the leftmost and rightmost squares, respectively. The black dashed line shows that a direct connection would cross four wires, whereas the optimal solution crosses only two wires (the curved blue line). ## Input The input consists of a single test case. The first line contains five integers m,x0,y0,x1,y1 m, x_0, y_0, x_1, y_1 , which are the number of pre-existing wires (m100 m \leq 100 ) and the start and end points that need to be connected. This is followed by m m lines, each containing four integers xa,ya,xb,yb x_a, y_a, x_b, y_b describing an existing wire of non-zero length from (xa,ya)(x_a, y_a) to (xb,yb)(x_b, y_b). The absolute value of each input coordinate is less than 105 10^5 . Each pair of wires has at most one point in common, that is, wires do not overlap. The start and end points for the new wire do not lie on a pre-existing wire. ## Output Display the minimum number of wires that have to be crossed to connect the start and end points. ## Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Description

Moore’s Law states that the number of transistors on a chip will double every two years. Amazingly, this law has held true for over half a century. Whenever current technology no longer allowed more growth, researchers have come up with new manufacturing technologies to pack circuits even denser. In the near future, this might mean that chips are constructed in three dimensions instead of two. But for this problem, two dimensions will be enough.

A problem common to all two-dimensional hardware design (for example chips, graphics cards, motherboards, and so on) is wire placement. Whenever wires are routed on the hardware, it is problematic if they have to cross each other. When a crossing occurs, special gadgets have to be used to allow two electrical wires to pass over each other, and this makes manufacturing more expensive.

Our problem is the following: you are given a hardware design with several wires already in place (all of them straight line segments). You are also given the start and end points for a new wire connection to be added. You will have to determine the minimum number of existing wires that have to be crossed in order to connect the start and end points. This connection need not be a straight line. The only requirement is that it cannot cross at a point where two or more wires already meet or intersect.

Figure L.1 shows the first sample input. Eight existing wires form five squares. The start and end points of the new connection are in the leftmost and rightmost squares, respectively. The black dashed line shows that a direct connection would cross four wires, whereas the optimal solution crosses only two wires (the curved blue line).

## Input

The input consists of a single test case. The first line contains five integers m,x₀,y₀,x₁,y₁, which are the number of pre-existing wires (m≤100) and the start and end points that need to be connected. This is followed by m lines, each containing four integers x_(a),y_(a),x_(b),y_(b) describing an existing wire of non-zero length from (x_(a),y_(a)) to (x_(b),y_(b)). The absolute value of each input coordinate is less than 10⁵.

Each pair of wires has at most one point in common, that is, wires do not overlap. The start and end points for the new wire do not lie on a pre-existing wire.

## Output

Display the minimum number of wires that have to be crossed to connect the start and end points.

## Sample Input 1

Original LaTeX notation
## Problem Description

Moore’s Law states that the number of transistors on a chip will double every two years. Amazingly, this law has held true for over half a century. Whenever current technology no longer allowed more growth, researchers have come up with new manufacturing technologies to pack circuits even denser. In the near future, this might mean that chips are constructed in three dimensions instead of two. But for this problem, two dimensions will be enough.

A problem common to all two-dimensional hardware design (for example chips, graphics cards, motherboards, and so on) is wire placement. Whenever wires are routed on the hardware, it is problematic if they have to cross each other. When a crossing occurs, special gadgets have to be used to allow two electrical wires to pass over each other, and this makes manufacturing more expensive.

Our problem is the following: you are given a hardware design with several wires already in place (all of them straight line segments). You are also given the start and end points for a new wire connection to be added. You will have to determine the minimum number of existing wires that have to be crossed in order to connect the start and end points. This connection need not be a straight line. The only requirement is that it cannot cross at a point where two or more wires already meet or intersect.

Figure L.1 shows the first sample input. Eight existing wires form five squares. The start and end points of the new connection are in the leftmost and rightmost squares, respectively. The black dashed line shows that a direct connection would cross four wires, whereas the optimal solution crosses only two wires (the curved blue line).

## Input

The input consists of a single test case. The first line contains five integers \( m, x_0, y_0, x_1, y_1 \), which are the number of pre-existing wires (\( m \leq 100 \)) and the start and end points that need to be connected. This is followed by \( m \) lines, each containing four integers \( x_a, y_a, x_b, y_b \) describing an existing wire of non-zero length from \((x_a, y_a)\) to \((x_b, y_b)\). The absolute value of each input coordinate is less than \( 10^5 \).

Each pair of wires has at most one point in common, that is, wires do not overlap. The start and end points for the new wire do not lie on a pre-existing wire.

## Output

Display the minimum number of wires that have to be crossed to connect the start and end points.

## Sample Input 1

Code

8 3 3 19 3
0 1 22 1
0 5 22 5
1 0 1 6
5 0 5 6
9 0 9 6
13 0 13 6
17 0 17 6
21 0 21 6

## Sample Output 1

Code

2

## Sample Input 2

Code

1 0 5 10 5
0 0 10 10

## Sample Output 2

Code

0

platform

atcoder

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import