求助DTOI T1最后一个子任务第三个点(#18)错误
  • 板块学术版
  • 楼主lwx20211103
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/2/1 18:11
  • 上次更新2023/10/24 02:11:30
查看原帖
求助DTOI T1最后一个子任务第三个点(#18)错误
727008
lwx20211103楼主2023/2/1 18:11
#include <bits/stdc++.h> //I AK IOI.
#define int long long
using namespace std;

bool check(long long n, long long maxn, long long minn)
{
	long long de = (3 * n * n + (n << 1)) >> 3;
	if (maxn > de)
	{
		return false;
	}
	if (maxn + minn > (n * (n + 1)) >> 1)
	{
		return false;
	}
	return true;
}

main()
{
	ios::sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--)
	{
		long long n, a, b;
		cin >> n >> a >> b;
		long long x = max(a, b), y = min(a, b);
		if (!check(n, x, y))
		{
			cout << -1;
		}
		else
		{
			stack<int> s;
			vector<int> v1, v2;
			for (int i = 1; i <= n; i++)
			{
				v1.push_back(i);
			}
			if (a == 0)
			{
				for (auto &&i : v1)
				{
					cout << i << " ";
				}
				cout << "\n";
				continue;
			}
			if (b == 0)
			{
				reverse(v1.begin(), v1.end());
				for (auto &&i : v1)
				{
					cout << i << " ";
				}
				cout << "\n";
				continue;
			}
			if (n <= 10)
			{
				do
				{
					int sum1 = 0, sum2 = 0;
					for (int i = 0; i < (n >> 1); i++)
					{
						sum1 += v1[i];
					}
					for (int i = (n >> 1); i < n; i++)
					{
						sum2 += v1[i];
					}
					if (sum1 >= a && sum2 >= b) 
					{
						for (auto &&i : v1)
						{
							cout << i << " ";
						}
						break;
					}
					//cout << sum1 << " " << sum2 << "\n";
				} while (next_permutation(v1.begin(), v1.end()));
			}
			else
			{
				v1.clear();
				for (int i = 1; i <= n; i++)
				{
					v1.push_back(i);
				}
				if (x <= n)
				{
					for (auto &&i : v1)
					{
						cout << i << " ";
					}
				}
				else
				{
					int i = 0;
					while (true)
					{
						if (lower_bound(v1.begin(), v1.end(), x) != v1.end())
						{
							s.push(*lower_bound(v1.begin(), v1.end(), x));
							v1.erase(lower_bound(v1.begin(), v1.end(), x));
							break;
						}
						else
						{
							x -= v1.back();
							s.push(v1.back());
							v1.pop_back();
						}
						i++;
					}
					while (i != n >> 1)
					{
						s.push(v1.front());
						v1.erase(v1.begin());
						i++;
					}
					if (b == max(a, b))
					{
						for (auto &&i : v1)
						{
							cout << i << " "; 
						}
						while (!s.empty())
						{
							cout << s.top() << " ";
							s.pop();
						}
					}
					else
					{
						while (!s.empty())
						{
							cout << s.top() << " ";
							s.pop();
						}
						for (auto &&i : v1)
						{
							cout << i << " "; 
						}
					}
				}
			}
		}
		cout << "\n";
	}
	return 0;
}

找不到 bug ,太抓狂了。我太菜了

2023/2/1 18:11
加载中...