CodeForces - 620A Efim and Strange Grade(贪心)

题目:传送门
思路: 很简单的贪心题,很明显斜着走是最优的行动方式(因为x,y两个方向都会移动),那我们先斜着走,走到没必要斜着走了再横着或竖着走即可,所以结果一定是水平距离和竖着距离中的最大值。

#include <iostream>
#include <algorithm>
using namespace std;
int ab(int x) {
	return x>=0? x:-x;
}
int main() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int maxs = max(ab(x1-x2),ab(y1-y2));
	cout<<maxs<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43305984/article/details/88985463
今日推荐