求助,最后一个测试点没过
查看原帖
求助,最后一个测试点没过
1356325
Besokus楼主2025/2/4 20:52

求助,最后一个测试点没过,求大佬帮忙看看代码

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int a[1005][1005];
int w;

int judge(int n, int m) {
	int index = 0;
	if (n % 2 == 0) {//偶数楼层
		index = m - 1;
	}
	else {
		index = w - m;
	}
	return index;
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int  m, n;
	cin >> w >> m >> n;
	int step = 0;
	//判断楼层
	int m_ = m / (w + 1);
	int n_ = n / (w + 1);
	//处理下标
	int _m = judge(m_, m % w);
	int _n = judge(n_, n % w);

	if (m_ == n_) {//同一楼层
		step = abs(_m - _n);
	}
	else {
		step = abs(m_ - n_) + abs(_m - _n);
	}
	cout << step;
	return 0;

}

2025/2/4 20:52
加载中...