Fence Painting
의견: 0
Several seasons of hot summers and cold winters have taken their toll on Farmer
John's fence, and he decides it is time to repaint it, along with the help of
his favorite cow, Bessie. Unfortunately, while Bessie is actually remarkably
proficient at painting, she is not as good at understanding Farmer John's
instructions.
If we regard the fence as a one-dimensional number line, Farmer
John paints the interval between \(x=a\) and \(x=b\). For example, if
\(a=3\) and \(b=5\), then Farmer John paints an interval of length 2.
Bessie, misunderstanding Farmer John's instructions, paints the
interval from \(x=c\) to \(x=d\), which may possibly overlap with part or
all of Farmer John's interval. Please determine the total length of
fence that is now covered with paint.
Problem credits: Brian Dean
Problem credits: Brian Dean
The first line of the input contains the integers \(a\) and \(b\), separated by a
space (\(a < b\)).
The second line contains integers \(c\) and \(d\), separated by a space (\(c < d\)).
The values of \(a\), \(b\), \(c\), and \(d\) all lie in the range \(0 \ldots 100\), inclusive.
Please output a single line containing the total length of the fence covered with paint.
paint.inpaint.out7 10
4 86Here, 6 total units of fence are covered with paint, from \(x=4\) all
the way through \(x=10\).
riseoj 작성
출처 올림피아드 > USACO > 2015-2016 > December > Bronze
평가 및 의견
Fence Painting
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Fence Painting