区间调度问题

#include
#include
using namespace std;

const int MAX_N = 100000;

int N, S[MAX_N], T[MAX_N];

pair itv[MAX_N];

void solve()
{
	for (int i = 0; i < N; i++)
	{
		itv[i].first = T[i];
		itv[i].second = S[i];
	}
	sort(itv, itv + N);

	int ans = 0, t = 0;
	for (int i = 0; i < N; i++)
	{
		if (t < itv[i].second)
		{
			ans++;
			t = itv[i].first;
		}
	}
	cout << ans << endl;
}

 

你可能感兴趣的:(挑战程序设计竞赛)