【CF1020A】New Building for SIS(签到)

题意:

有n栋楼,从一栋楼某个地方,到大另一栋楼的某个地方,每栋楼给了连接楼的天桥,每走一层或者穿个一栋楼花费一分钟,求出起点到大目的点最少花费的时间

n,h<=1e8,q<=1e4

思路:分类讨论

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<algorithm>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<vector>
11 using namespace std;
12 typedef long long ll;
13 typedef unsigned int uint;
14 typedef unsigned long long ull;
15 typedef pair<int,int> PII;
16 typedef vector<int> VI;
17 #define fi first
18 #define se second 
19 #define MP make_pair
20 #define N   1100000
21 #define MOD 1000000007
22 #define eps 1e-8 
23 #define pi acos(-1)
24 
25 int read()
26 { 
27    int v=0,f=1;
28    char c=getchar();
29    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
30    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
31    return v*f;
32 }
33     
34 void swap(int &x,int &y)
35 {
36     int t=x;x=y;y=t;
37 }
38 
39 int main()
40 {
41     //freopen("1.in","r",stdin);
42     //freopen("1.out","w",stdout);
43     int n,h,a,b,k;
44     scanf("%d%d%d%d%d",&n,&h,&a,&b,&k);
45     for(int i=1;i<=k;i++)
46     {
47         int x1,y1,x2,y2;
48         scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
49         int ans=1<<30;
50         ans=min(ans,abs(a-y1)+abs(x1-x2)+abs(a-y2));
51         ans=min(ans,abs(b-y1)+abs(x1-x2)+abs(b-y2));
52         if(a<=y1&&y1<=b) ans=min(ans,abs(x2-x1)+abs(y1-y2));
53         if(a<=y2&&y2<=b) ans=min(ans,abs(x2-x1)+abs(y1-y2));
54         if(x1==x2) ans=min(ans,abs(y1-y2));
55         printf("%d\n",ans);
56     }
57      

 

posted on 2018-10-24 13:55  myx12345  阅读(156)  评论(0编辑  收藏  举报

导航