#include<iostream>
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<n; i++)
{
cin >> x[i].s >> x[i].f;
x[i].key = i;
}
for (i = 0; i<n; i++)
{
for (j = i + 1; j<n; j++)
{
if (x[i].f>x[j].f)
{
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
atime(n, x, a);
return 0;
}
贪心算法之活动安排
最新推荐文章于 2024-09-29 23:33:11 发布