hdu 2037 今年暑假不ac(简单贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=2037


先对结束时间进行排序,然后用开始时间和上一个节目的结束时间来比较。

要是对开始时间进行比较,用结束时间来比较就不好了,因为不知道每个节目的长度,只知道开始时间比较难操作。确实我现在水平也打不出来。


#include <iostream>
using namespace std;

int main()
{
	int n;
	while(cin >> n && n != 0)
	{
		int ts[105]= {0}, te[105] = {0};
		int i = 0;
		while(n--)
		{
			cin >> ts[i] >> te[i];
			i++;
		}
	int k = 0, t = 0, num = i;
	//¶Ô½áβʱ¼ä½øÐÐÅÅÐò 
	for(k = 0; k < num - 1; k++)
		for(t = 0; t < num - 1 - k; t++)
		{
			if(te[t] > te[t + 1])
			{
				int e = ts[t];
				ts[t] = ts[t + 1];
				ts[t + 1] = e;
				int w = te[t];
				te[t] = te[t + 1];
				te[t + 1] = w;
			}
		} 
	int count = 1, b = te[0];
	for(int y = 0; y < num; y++)
	{
		for(int c = y + 1; c < num; c++)
		{
			if(ts[c] >= b)
			{
				y = c - 1;
				b = te[c];
				count++;
				break;
			}
		}
	} 
		cout << count << endl;
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值