贪心算法之活动安排

#include
using namespace std;

struct data{
	int s, f, key;
};

void atime(int n, data *x, int *a)
{
	a[0] = 1;
	int j = 0, i;
	for (i = 1; i < n; i++)
	{
		if (x[i].s >= x[j].f)
		{
			a[x[i].key] = 1;
			j = i;
		}
		else
			a[x[i].key] = 0;
	}
	for (i = 0; i < n; i++)
		cout << a[i] << " ";
}

int main()
{
	int i, n, j;
	int *a;
	data *x, temp;
	cin >> n;
	x = new data[n + 1];
	a = new int[n + 1];
	for (i = 0; i> x[i].s >> x[i].f;
		x[i].key = i;
	}
	for (i = 0; ix[j].f)
			{
				temp = x[i];
				x[i] = x[j];
				x[j] = temp;
			}
		}
	}
	atime(n, x, a);
	return 0;
}

你可能感兴趣的:(贪心算法之活动安排)