图书馆占位
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);
}
}
}
}