【CodeForces - 1020A】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.
Input
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
Input
3 6 2 3 3 1 2 1 3 1 4 3 4 1 2 2 3Output
1 4 2題目大意:
第一行n <= 10^8 代表樓房個數 第二行h <= 10^8 代表樓房高度 然后 a,b 兩個整數代表第a樓到第b樓有空中電梯 有電梯的樓層,相鄰兩棟樓移動一步可以到達,每個樓的相鄰兩個樓層移動一步可以到達 然后 一個整數k <= 10^4 然后k行每行有ta fa tb fb 分別是 a b兩個地方的樓號 樓層號 輸出最少移動步數解題報告:
? ?直接模擬就行了,注意特殊樣例,比如在同一個樓的不同層里,比如在不同樓的同一層里。
AC代碼:
#include<bits/stdc++.h> #define ll long long using namespace std; int n,h,a,b,k; int main() {cin>>n>>h>>a>>b>>k;int t1,f1,t2,f2;int cur;ll ans = 0;while(k--) {ans = 0;scanf("%d%d%d%d",&t1,&f1,&t2,&f2);if(t1 == t2) {printf("%d\n",abs(f2-f1));continue;}if(t1 > t2) {swap(t1,t2);}if(f1>f2) swap(f1,f2);if(f1 <= a) ans += (a-f1),cur = a;else if(f1 >= b) ans += (f1 - b), cur = b;else cur = f1;ans += (t2-t1);ans += abs(cur - f2);printf("%lld\n",ans);}return 0 ; }?
總結
以上是生活随笔為你收集整理的【CodeForces - 1020A】New Building for SIS(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SMax4PNP.exe - SMax4
- 下一篇: 申请信用卡不用会怎样 小心“休眠”卡变成