luogu#P5045. [SCOI2003] 蜘蛛难题

[SCOI2003] 蜘蛛难题

Problem Description

There is a set of pipes and a spider Willy\text{Willy}, as shown in the figure below. All pipes are open at the top and sealed at the bottom. Each pipe has a diameter of 1cm1cm. The connections between two pipes have infinite capacity, but their volume can be ignored.

Above the first pipe there is a water source, from which water keeps flowing downward at a rate of 0.25cm30.25cm^3 per second. Since the cross-sectional area of a pipe is 0.25cm20.25cm^2, when filling only one pipe, the water level rises by 1cm1cm per second. According to physics, during the first 22 seconds, the water flows into the bottom of the left pipe; during seconds [3,5][3,5], it flows into the right pipe; during seconds [6,9][6,9], it flows into both pipes at the same time (although the total flow rate is unchanged, because two pipes are filled simultaneously, the rising speed in each pipe is only 0.5cm0.5cm per second), and then it reaches the spider.

Given the positions of the connections between pipes and the position of the spider Willy\text{Willy}, find the time when the water level touches Willy\text{Willy}. Assume the spider’s actual position is slightly higher than the given one. Therefore, if the spider is at position n=4n=4 in the left pipe, the answer should be 55 seconds. This is because after the first two seconds the water level seems to touch Willy\text{Willy}, but it is actually slightly below Willy\text{Willy}.

Input Format

All positions are represented by ordered pairs (x,y)(x, y), where the yy coordinate increases from top to bottom, and the xx coordinate increases from left to right. Therefore, the top-left corner is (0,0)(0,0). All other coordinate values are integers between 00 and 100100.

The first line contains an integer p(1<=p<=20)p(1<=p<=20), the number of pipes. The next pp lines each contain three integers x,y,hx, y, h describing one pipe. (x,y)(x,y) is the coordinate of the top-left corner of the pipe, and hh is the height of the pipe (1<=h<=20)(1<=h<=20).

The next line contains an integer L(0<=L<=50)L(0<=L<=50), the number of connections.

The next LL lines each contain three integers x,y,dx, y, d describing a connection. (x,y)(x,y) is the coordinate of the left endpoint, and dd is the length of the connection (1<=d<=20)(1<=d<=20).

The last line contains two integers a,ba,b, meaning that Willy\text{Willy} is in pipe aa at the position whose yy coordinate is bb. Pipes are numbered 1,2,3p1,2,3…p in the order they appear in the input file.

The following assumptions hold: the water source is always directly above the first pipe; connections do not cross pipes; the yy coordinates of any two connections are different; the xx coordinates of the top-left corners of any two pipes are different; and both endpoints of every connection lie on pipes (there will be no “hanging” endpoints).

Output Format

Output only one integer: the time when the water level touches Willy\text{Willy}. If the water level can never touch Willy\text{Willy}, output 1-1.

2
2 0 6
5 1 6
1
3 4 2
2 2
9

Hint

Translated by ChatGPT 5