10分蒟蒻悬赏求助!!!(关注)
查看原帖
10分蒟蒻悬赏求助!!!(关注)
857568
HanZig楼主2023/6/19 18:58

写了很长一段代码,结果总是10分(想砸电脑的冲动)……写了很长一段代码,结果总是10分(想砸电脑的冲动)……

#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
void bubble_sort(vector <int> q[2])
{
	for (int i = 0; i < q[1].size(); i++)
	{
		for (int j = i; j < q[1].size() - 1; j++)
		{
			if (q[1][j] >= q[1][j + 1])
			{
				int &x = q[0][j], &y = q[0][j + 1];
				swap(x, y);
				int &x1 = q[1][j], &y1 = q[1][j + 1];
				swap(x1, y1);
			}
			else
			{
				break;
			}
		}
	}
}
int main()
{
	int n, m, heng, shu, p;
	cin >> n >> m >> heng >> shu >> p;
	int x1, y1, x2, y2;
	for (int i = 1; i <= p; i++)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		a[x1][y1] = i;
		a[x2][y2] = i;
	}
	vector <int> num1[2], num2[2];
	num1[0].resize(n + 1);
	num1[1].resize(n + 1);
	num2[0].resize(m + 1);
	num2[1].resize(m + 1);
	for (int i = 1; i <= n - 1; i++)
	{
		int cnt = 0;
		for (int j = 1; j <= m; j++)
		{
			if (a[i][j] == a[i + 1][j] && a[i][j] != 0)
			{
				cnt++;
			}
		}
		num1[0].push_back(i);
		num1[1].push_back(cnt);
	}
	for (int i = 1; i <= m - 1; i++)
	{
		int cnt = 0;
		for (int j = 1; j <= n; j++)
		{
			if (a[j][i] == a[j][i + 1] && a[j][i] != 0)
			{
				cnt++;
			}
		}
		num2[0].push_back(i);
		num2[1].push_back(cnt);
	}
	bubble_sort(num1);
	bubble_sort(num2);
	for (int i = num1[1].size() - heng + 1; i <= num1[1].size() - 1; i++)
	{
		printf("%d ", num1[0][i]);
	}
	printf("%d\n", num1[0][num1[1].size() - heng]);
	for (int i = num2[1].size() - shu + 1; i <= num2[1].size() - 1; i++)
	{
		printf("%d ", num2[0][i]);
	}
	printf("%d", num2[0][num2[1].size() - shu]);
	return 0;
}
2023/6/19 18:58
加载中...