样例过,自测数据过,全RE
查看原帖
样例过,自测数据过,全RE
634199
zhao_hong_hao楼主2021/12/9 14:01
//出现C6262警告,Segmentation fault with invalid memory
#include <stdio.h>
#include <math.h>

int main()
{
	int a[100];
	int b[100];
	int c[100];
	int d[100];
	long i;
	int t;
	int compb(int, int);
	int comps(int, int);
	int func(int);

	scanf("%d",&t);
	for (i = 0;  i < t; i++)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);

	for(i=0;i<t;i++)
	{	
		int step, x, y;
		x = abs(c[i]- a[i]);
		y = abs(d[i] - b[i]);
		step = comps(x, y) * 2;
		step += func(compb(x, y) - step / 2);
		printf("%d\n", step);
	}
	return 0;
}
int compb(int a, int b)
{
	int max;
	max = a > b ? a: b;
	return(max);
}
int comps(int a, int b)
{
	int min;
	min = a < b ? a : b;
	return(min);
}
int func(int a)//2、3判断,最后步数计算
{
	int ans;
	if (a == 1)
		ans = 1;

	if (a % 2 == 0)
		ans = (a / 2) * 4;
	else
		ans = ((a - 3) / 2) * 4 + 5;
	return ans;
}
2021/12/9 14:01
加载中...