HRBUST1315-火影忍者之~大战之后

火影忍者之~大战之后
Time Limit: 1000 MSMemory Limit: 32767 K
Total Submit: 432(189 users)Total Accepted: 244(178 users)Rating: Special Judge: No
Description

经历了大战的木叶村现在急需重建,人手又少,所以需要尽可能多的接受外来的任务,以赚取报酬,重建村庄,假设你现在是木叶的一名高级忍者,有一大堆的任务等着你来做,但毕竟个人时间有限,所以没办法将所有的任务都做了,而只能尽可能的多。

Input
每组数据包括一个整数n,表示分配给你的任务总数,然后n行,每行两个整数,分别表示任务开始以及结束时间,输入到0结束。n不超过100,每个时间值不超过1000
Output
对每组数据,输出能够执行的最多任务数。
Sample Input
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0
Sample Output
5
Source
2012 Spring Contest 3 - STL
Author
拂晓


解题思路:对所有任务重新排序,越早结束的越在前面

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define LL long long
const int INF=0x3f3f3f3f;

struct node
{
    int s,e;
}x[200];

bool cmp(node x,node y)
{
    return x.e<y.e;
}

int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        for(int i=1;i<=n;i++)
            scanf("%d %d",&x[i].s,&x[i].e);
        sort(x+1,x+1+n,cmp);
        int sum=1;
        int k=x[1].e;
        for(int i=2;i<=n;i++)
        {
            if(x[i].s>=k)
            {
                sum++;
                k=x[i].e;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值