求大佬指点,测试点2没有过
查看原帖
求大佬指点,测试点2没有过
1459393
Dwz2006楼主2025/1/18 13:15

这个是整个操作的函数、

bool func(int n,int &ans, vector<int> arr_1, vector<int> arr_2)
{
	while (1)
	{
		if (ans > 30)
		{
			return false;
		}
		bool judge = true;
		if (arr_1.size() == 2)
		{
			if (arr_1[0] != arr_1[1])
			{
				judge = false;
			}
		}
		else if(arr_1.size() > 2)
		{
			for (int i = 0; i < arr_1.size() / 2; i++)
			{
				if (arr_1[i] != arr_1[arr_1.size() - i - 1])
				{
					judge = false;
					break;
				}
			}
		}
		if (judge)
		{
			return true;
		}
		vector<int> arr;
		size_t size = arr_1.size();
		for (int i = size-1; i >= 0; i--)
		{
			int a = arr_1[i] + arr_2[i];
			if (a >= n)
			{
				int m = a % n;
				arr_1[i] = m;
				if (i == 0)
				{
					arr_1.insert(arr_1.begin(), 1);
				}
				else
				{
					arr_1[i - 1] += 1;
				}
			}
			else
			{
				arr_1[i] = a;
			}
			//arr.push_back(arr_1[i]);
		}
		//if (size != arr_1.size())
		//{
		//	arr.push_back(1);
		//}
		//arr_2 = arr;
		for (int v : arr_1)
		{
			arr.insert(arr.begin(), v);
		}
		arr_2 = arr;
		ans += 1;
	}
}
2025/1/18 13:15
加载中...