1087 -- 图书馆占位

图书馆占位

Time Limit:1000MS  Memory Limit:65536K
Total Submit:134 Accepted:51

Description

图书馆占位的很厉害,只要去晚了一会就没有位置了。有些人占着位置却不来自习,这就造成了资源的浪费。现在我们的问题是一天当中有n个同学可能会来到同一个座位,假设上面有人则另外找座位,若没有人,则就可以占据此位置,直至你离开为止。为了最大化利用图书馆资源,我们要求的问题是一个位置最多能够被几个同学来用过。

Input

多组测试数据
第一行为n个同学 (1 <=n<=10000)
接下来n行就是每个同学的进入图书馆的时间和离开图书馆的时间,为了简化问题,我们假设时间值为整数。

Output

输出一个座位最多被几位同学占据。

Sample Input

6
1 3
2 4
3 6
7 9
5 7
10 11

Sample Output

4

Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1087 {
    class Program {
        struct Time {
            public int start;
            public int end;
        }
        public class MyComparer : IComparer<Time> {
            int IComparer<Time>.Compare(Time a , Time b) {
                return a.end < b.end ? -1 : 1;
            }
        }
        static void Main(string[] args) {
            string s;
            while ((s = Console.ReadLine()) != null) {
                int n = int.Parse(s);
                Time[] a = new Time[n + 5];
                for (int i = 0 ; i < n ; i++) {
                    string[] ss = Console.ReadLine().Split();
                    a[i].start = int.Parse(ss[0]);
                    a[i].end = int.Parse(ss[1]);
                }
                Array.Sort(a , 0 , n , new MyComparer());
                int count = 1 , temp = a[0].end;
                for (int i = 1 ; i < n ; i++) {
                    if (a[i].start >= temp) {
                        count++;
                        temp = a[i].end;
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值