只有第八个测试点WA了,求调,显示too long on line 2
查看原帖
只有第八个测试点WA了,求调,显示too long on line 2
1268242
EumenidesHe楼主2024/3/17 12:17
#include<iostream>
#include<algorithm>
using namespace std;
char c[800][3100];
int m, n, p, q,h=3,w=3,l=1,cnt=1;
pair<int, int>a[15];
bool cmp(pair<int, int>a, pair<int, int>b)
{
	if (a.first == b.first)return a.second < b.second;
	else if (a.first > b.first)
	{
		while (a.first > b.first)
		{
			a.first -= 1;
			a.second = (a.second + 1) / 2;
		}
		return a.second < b.second;
	}
	else if (a.first < b.first)
	{
		while (a.first < b.first)
		{
			b.first -= 1;
			b.second = (b.second + 1) / 2;
		}
		return a.second < b.second;
	}
}
void Bfs(int i, int j,int x,int y)
{
	/*if (x == a[cnt].first && y == a[cnt].second)
	{
		cnt++;
		return;
	}*/
	if (x == m - 1)
	{
		c[i][j] = 'o';
		int i1 = i, i2 = i, j1 = j, j2 = j;
		if (x + 1 != a[cnt].first || 2 * y-1 != a[cnt].second)
		{
			c[++i1][--j1] = '/';
			Bfs(++i1, --j1, x + 1, 2 * y - 1);
		}
		else cnt++;
		if (x + 1 != a[cnt].first || 2 * y != a[cnt].second)
		{
			c[++i2][++j2] = '\\';
			Bfs(++i2, ++j2, x + 1, 2 * y);
		}
		else cnt++;
		return;
	}
	else if (x == m)
	{
		c[i][j] = 'o';
		return;
	}
	c[i][j] = 'o';
	int i1 = i, i2 = i, j1 = j, j2 = j;
	int h1 = h;
	for (int k = 0; k < x; k++)h1 /= 2;
	h1 -= 1;
	if (x + 1 != a[cnt].first || 2 * y - 1 != a[cnt].second)
	{
		for (int k = 0; k < h1; k++)
		{
			i1++;
			j1--;
			c[i1][j1] = '/';
		}
		i1++, j1--;
		Bfs(i1, j1, x + 1, 2 * y - 1);
	}
	else cnt++;
	if (x + 1 != a[cnt].first || 2 * y != a[cnt].second)
	{
		for (int k = 0; k < h1; k++)
		{
			i2++;
			j2++;
			c[i2][j2] = '\\';
		}
		i2++, j2++;
		Bfs(i2, j2, x + 1, 2 * y);
	}
	else cnt++;
}
int main()
{
	cin >> m >> n;
	for (int i = 0; i < m - 2; i++)h *= 2;
	for (int i = 0; i < m-1; i++)w *= 2;
	w -= 1;
	//for (int i = 0; i < m - 1; i++)l *= 2;
	for (int i = 1; i <= n; i++)cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1,cmp);
	/*for (int i = 1; i <= m; i++)
	{
		if
		for (int j = 1; j <= l; j++)
		{
			if (i == a[cnt].first && j == a[cnt].second)
			{
				cnt++;
				continue;
			}

		}
		l *= 2;
	}*/
	Bfs(1, (w + 1) / 2, 1, 1);
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (!c[i][j])cout << ' ';
			else cout << c[i][j];
		}
		cout << '\n';
	}
}
2024/3/17 12:17
加载中...