A1025 | Fence Painting--Bronze
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/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.
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.
输入格式
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.
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.
with paint.
输入输出样例
输入 #1
7 10 4 8
输出 #1
6
Here, 6 total units of fence are covered with paint, from $x=4$ all the way
through $x=10$.
through $x=10$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted