cf Round #503 (Div. 2) A: New Building for SIS (思维)

题目链接:

New Building for SIS

题意:

楼楼间有通道;

给出k个查询;

求起点到终点的最短路线;

思路:

思路其实很简单,就是一道水题,但是无奈思维太差,比赛时候一直没考虑到如果他起点和终点在同一个楼,比如1 6 1 8;

而通道在比如2 3,那么他没有必要从6到3再到8,直接6到8就好啦;

而我当时写的代码没有考虑到这种情况,比赛时一直是wa,也找不出什么原因,直到比赛后问师傅才恍然大悟,简直被蠢哭啦,因此那场比赛负了90+的rating,不过那是我在cf的第一场网络赛,未来也未可知,我会继续加油!

AC代码如下:

#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main()
{
	int n,h,a,b,k;
	scanf("%d%d%d%d%d",&n,&h,&a,&b,&k);
	for(int i=0;i<k;i++)
	{
		int ta,fa,tb,fb,sum=0;
		scanf("%d%d%d%d",&ta,&fa,&tb,&fb);
		if(ta!=tb)
		{
			if(fa>=a&&fa<=b)
			{
				sum=sum+abs(tb-ta);
				sum=sum+abs(fb-fa);
				printf("%d\n",sum);
			}
			else if(fa<a)
			{
				sum=sum+abs(fa-a);
				sum=sum+abs(tb-ta);
				sum=sum+abs(fb-a);
				printf("%d\n",sum);
			}
			else if(fa>b)
			{
				sum=sum+abs(fa-b);
				sum=sum+abs(tb-ta);
				sum=sum+abs(fb-b);
				printf("%d\n",sum);
			}
		}
		else
		{
			printf("%d\n",abs(fb-fa));//注意,当在同一层楼中走动时,不用管楼楼间的通道!
		}
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值