
本题的大意是一个青蛙从原点开始跳格子(0,0),最终要跳到点(x,y)去,并且每一步的步长不能超过k,问最短几步可以跳到终点
分析:
本题利用贪心思想,肯定是先跳最大的步长这样总体用的步数最长
代码演示:
#include <iostream>
using namespace std;
int main(void)
{
	int t;cin >> t;
	while(t--)
	{
		int x,y,k;
		cin >> x >> y >> k;
		// x方向先跳完,可以少走一步,这是要注意的 
		if(x>=y) cout << (x+k-1)/k+max((x+k-1)/k-1,(y+k-1)/k) << endl;
		else cout << (y+k-1)/k*2 << endl;
	}
	
	return 0;
} 
感谢查看!


















![[SAP ABAP] 清空ABAP变量](https://i-blog.csdnimg.cn/direct/e665b67746b042879002d438fe3c001e.png)
