A - New Building for SIS
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 (ta, fa), (tb, fb): floor fa of tower ta and floor fb of tower tb. 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 ≤ 108),
- h: the number of floors in each tower (1 ≤ h ≤ 108),
- 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 ≤ 104).
Next k lines contain description of the queries. Each description consists of four integers ta, fa, tb, fb (1 ≤ ta, tb ≤ n, 1 ≤ fa, fb ≤ h). This corresponds to a query to find the minimum travel time between fa-th floor of the ta-th tower and fb-th floor of the tb-th tower.
Output
For each query print a single integer: the minimum walking time between the locations in minutes.
Example
3 6 2 3 3
1 2 1 3
1 4 3 4
1 2 2 3
1
4
2
题意:一个人在楼之间穿梭,不同楼层之间通过的楼梯给出范围,穿梭楼层以及不同楼之间的时间为1min,求从目标地到最后的地方需要最少的时间
题解:该题有个大坑-----此人可能在一栋楼上,那么不需要考虑楼层之间的问题;(万幸吃个零食想了出来orz)
那么情况分为两种:
一种是一栋楼,,直接做差即可;
第二种是不同楼,画图可知----走弯路情况只有两种(一个是目的地和出发的都在规定楼层上面,一个是在规定楼层下面),其余情况做差就可
注意:做差时加绝对值
ac代码
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,h,low,hig,k;
int main()
{
long long ans;
int ta,fa,tb,fb;
cin>>n>>h>>low>>hig>>k;
for(int i=1; i<=k; i++)
{
cin>>ta>>fa>>tb>>fb;
if(ta==tb)
ans=abs(fa-fb);
else
{
ans=abs(tb-ta);
if(fa<low&&fb<low)
ans+=(low-fa+low-fb);
else if(fa>hig&&fb>hig)
ans+=(fa-hig+fb-hig);
else
ans+=abs(fa-fb);
}
cout<<ans<<endl;
}
return 0;
}
A - New Building for SIS的更多相关文章
- A. New Building for SIS Codeforce
You are looking at the floor plan of the Summer Informatics School's new building. You were tasked w ...
- 【CF1020A】New Building for SIS(签到)
题意: 有n栋楼,从一栋楼某个地方,到大另一栋楼的某个地方,每栋楼给了连接楼的天桥,每走一层或者穿个一栋楼花费一分钟,求出起点到大目的点最少花费的时间 n,h<=1e8,q<=1e4 思路 ...
- Codeforces Round #503 (by SIS, Div. 2) Solution
从这里开始 题目列表 瞎扯 Problem A New Building for SIS Problem B Badge Problem C Elections Problem D The hat P ...
- CF-503div2-A/B/C
A. New Building for SIS time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #503 Div. 2
时间相对来说还是比较合适的,正好放假就可以打一打啦. A. New Building for SIS:http://codeforces.com/contest/1020/problem/A 题意概述 ...
- Building the Testing Pipeline
This essay is a part of my knowledge sharing session slides which are shared for development and qua ...
- BZOJ 4742: [Usaco2016 Dec]Team Building
4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 21 Solved: 16[Su ...
- Building OpenCASCADE on Debian
Building OpenCASCADE on Debian eryar@163.com Abstract. When you are familiar with OpenCASCADE on Win ...
- Building third-party products of OpenCascade
Building third-party products of OpenCascade eryar@163.com Available distributives of third-party pr ...
随机推荐
- ECSHOP后台左侧添加菜单栏
比如我们在后台中增加 “活动管理”功能,方法如下 在ECSHOP 管理中心共用语言文件 language\zh_cn\admin\commn.php ,添加我们的自定义菜单: $_LANG['17_a ...
- Python3-configparser模块-配置文件解析器
Python3中的configparser模块主要用于处理类似于windows ini 文件结构的配置文件 1.configparser模块提供实现基本配置语言的ConfigParser类 2.配置文 ...
- 如何用Tesseract做日文OCR(c#实现)
首先做一下背景介绍,Tesseract是一个开源的OCR组件,主要针对的是打印体的文字识别,对手写的文字识别能力较差,支持多国语言(中文.英文.日文.韩文等).是开源世界里最强的一款OCR组件.当然和 ...
- BZOJ 4055 Misc
原题传送门 比较复杂的一道DP. 设两点(i,j)之间最短路为dis[i][j],则 可转化为: 将该式前后分立,可得: 其中,可以单独求出,后面的部分则需要DP. 设为b(x),枚举i,并计算出从i ...
- Linux高并发网络编程开发——10-Linux系统编程-第10天(网络编程基础-socket)
在学习Linux高并发网络编程开发总结了笔记,并分享出来.有问题请及时联系博主:Alliswell_WP,转载请注明出处. 10-Linux系统编程-第10天(网络编程基础-socket) 在学习Li ...
- Emergency Evacuation 题解
The Japanese government plans to increase the number of inbound tourists to forty million in the yea ...
- day42 io模型
目录 一.io模型简介 二.阻塞io阻塞IO模型图.png 三.非阻塞io 四.io多路复用 五.异步io 一.io模型简介 Stevens在文章中一共比较了五种IO Model: blocking ...
- Django setting设置 常用设置
目录 Django配置文件基本设置 前言 setting配置汇总 一.APP路径 二.数据库配置 三.sql语句展示 四.静态文件目录 五.media文件配置 六.数据库中的UserInfo(用户表) ...
- JVM 专题二十:垃圾回收(四)垃圾回收器 (一)
1. GC分类与性能指标 垃圾收集器没有在规范中进行过多的规定,可以由不同的厂商.不同版本的JVM来实现.由于JDK的版本处于高速迭代过程中,因此Java发展至今已经产生了众多的GC版本.从不同角度分 ...
- java 面向对象(三十七):反射(一) 反射的概述
1.本章的主要内容 2.关于反射的理解 Reflection(反射)是被视为动态语言的关键,反射机制允许程序在执行期借助于Reflection API取得任何类的内部信息,并能直接操作任意对象的内部属 ...