A987 | Springboards--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Bessie is in a 2D grid where walking is permitted only in directions parallel
to one of the coordinate axes. She starts at the point $(0,0)$ and wishes to
reach $(N,N)$ ($1\le N\le 10^9$). To help her out, there are $P$ ($1\le P\le
10^5$) springboards on the grid. Each springboard is at a fixed point
$(x_1,y_1)$ and if Bessie uses it, she will land at a point $(x_2,y_2)$.
Bessie is a progress-oriented cow, so she only permits herself to walk up or
right, never left nor down. Likewise, each springboard is configured to never
go left nor down. What is the minimum distance Bessie needs to walk?
to one of the coordinate axes. She starts at the point $(0,0)$ and wishes to
reach $(N,N)$ ($1\le N\le 10^9$). To help her out, there are $P$ ($1\le P\le
10^5$) springboards on the grid. Each springboard is at a fixed point
$(x_1,y_1)$ and if Bessie uses it, she will land at a point $(x_2,y_2)$.
Bessie is a progress-oriented cow, so she only permits herself to walk up or
right, never left nor down. Likewise, each springboard is configured to never
go left nor down. What is the minimum distance Bessie needs to walk?
输入格式
Output a single integer, the minimum distance Bessie needs to walk to reach
$(N,N)$.
$(N,N)$.
输出格式
The fist line contains two space-separated integers $N$ and $P$.
The next $P$ lines each contains four integers, $x_1$, $y_1$, $x_2$, $y_2$,
where $x_1 \le x_2$ and $y_1 \le y_2.$
All springboard and target locations are distinct.
The next $P$ lines each contains four integers, $x_1$, $y_1$, $x_2$, $y_2$,
where $x_1 \le x_2$ and $y_1 \le y_2.$
All springboard and target locations are distinct.
输入输出样例
输入 #1
3 2 0 1 0 2 1 2 2 3
输出 #1
3
* Test cases 2-5 satisfy $P \le 1000$.
* Test cases 6-15 satisfy no additional constraints.
* Test cases 6-15 satisfy no additional constraints.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted