A11873 | New Building for SIS
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room.
The building consists of $n$ towers, $h$ floors each, where the towers are labeled from $1$ to $n$ , the floors are labeled from $1$ to $h$ . There is a passage between any two adjacent towers (two towers $i$ and $i+1$ for all $i$ : $1<=i<=n-1$ ) on every floor $x$ , where $a<=x<=b$ . It takes exactly one minute to walk between any two adjacent floors of a tower, as well as between any two adjacent towers, provided that there is a passage on that floor. It is not permitted to leave the building.
The picture illustrates the first example.
You have given $k$ pairs of locations $(t_{a},f_{a})$ , $(t_{b},f_{b})$ : floor $f_{a}$ of tower $t_{a}$ and floor $f_{b}$ of tower $t_{b}$ . For each pair you need to determine the minimum walking time between these locations.
The building consists of $n$ towers, $h$ floors each, where the towers are labeled from $1$ to $n$ , the floors are labeled from $1$ to $h$ . There is a passage between any two adjacent towers (two towers $i$ and $i+1$ for all $i$ : $1<=i<=n-1$ ) on every floor $x$ , where $a<=x<=b$ . It takes exactly one minute to walk between any two adjacent floors of a tower, as well as between any two adjacent towers, provided that there is a passage on that floor. It is not permitted to leave the building.
The picture illustrates the first example.
You have given $k$ pairs of locations $(t_{a},f_{a})$ , $(t_{b},f_{b})$ : floor $f_{a}$ of tower $t_{a}$ and floor $f_{b}$ of tower $t_{b}$ . For each pair you need to determine the minimum walking time between these locations.
输入格式
The first line of the input contains following integers:
- $n$ : the number of towers in the building ( $1<=n<=10^{8}$ ),
- $h$ : the number of floors in each tower ( $1<=h<=10^{8}$ ),
- $a$ and $b$ : the lowest and highest floor where it's possible to move between adjacent towers ( $1<=a<=b<=h$ ),
- $k$ : total number of queries ( $1<=k<=10^{4}$ ).
Next $k$ lines contain description of the queries. Each description consists of four integers $t_{a}$ , $f_{a}$ , $t_{b}$ , $f_{b}$ ( $1<=t_{a},t_{b}<=n$ , $1<=f_{a},f_{b}<=h$ ). This corresponds to a query to find the minimum travel time between $f_{a}$ -th floor of the $t_{a}$ -th tower and $f_{b}$ -th floor of the $t_{b}$ -th tower.
- $n$ : the number of towers in the building ( $1<=n<=10^{8}$ ),
- $h$ : the number of floors in each tower ( $1<=h<=10^{8}$ ),
- $a$ and $b$ : the lowest and highest floor where it's possible to move between adjacent towers ( $1<=a<=b<=h$ ),
- $k$ : total number of queries ( $1<=k<=10^{4}$ ).
Next $k$ lines contain description of the queries. Each description consists of four integers $t_{a}$ , $f_{a}$ , $t_{b}$ , $f_{b}$ ( $1<=t_{a},t_{b}<=n$ , $1<=f_{a},f_{b}<=h$ ). This corresponds to a query to find the minimum travel time between $f_{a}$ -th floor of the $t_{a}$ -th tower and $f_{b}$ -th floor of the $t_{b}$ -th tower.
输出格式
For each query print a single integer: the minimum walking time between the locations in minutes.
输入输出样例
输入 #1
3 6 2 3 3 1 2 1 3 1 4 3 4 1 2 2 3
输出 #1
1 4 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted