A. Box is Pull

题目:
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x1,y1) to the point (x2,y2).

He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.

https://codeforces.com/contest/1428/problem/A

题意:
类似于推箱子的拉箱子,每次只能拉动一个格子,只能拉直线,拉一格需要一秒。那对于给出的任意两个点,只要他们在一条直线上,时间就是这两点的距离。如果不在一条直线上,那最短的路线就是两条直线,先将箱子从起点拉到与重终点在一条直线上,然后拉箱子的人改变方向(改变方向需要走两个格子),然后拉到终点。答案也就是两点间的距离加二。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long int res = 0;
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if(a==c)
		{
			res = abs(d-b);
			cout << res << endl;
			continue;
		}
		if(b==d)
		{
			res = abs(a-c);
			cout << res << endl;
			continue;
		}
		res = abs(a-c)+abs(b-d)+2;
		cout << res << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值