1301 - Monitoring Processes
Time Limit: 3 second(s) Memory Limit: 32 MB

We have planned to design a new operating system. Like other OS we will use the techniques of processes, schedulers, locks etc. The basic plan is to use the OS in hardwires that have low configurations. So, efficiency matters. That's why we want to minimize the cost as well as the power consumption. To be more specific, there are n processes, and each process starts its execution in timestamp si, and ends its execution in timestamp ti. For simplicity assume that the timestamps are represented as integers. Now when a process is being executed, we need a wrapper program to look after the process. The reason behind using wrapper programs is that, they will continuously check the processes and if any process tries to harm the system or wants to take hold of some restricted resources or even tries to invoke some forbidden methods, the wrapper will halt the process and generate appropriate error signals. But the problem is that a wrapper program cannot monitor more than one process in any timestamp and when it's been assigned to a process, it will have to wait until the process finishes. But after this, the same wrapper program can be used for monitoring another process. So, a wrapper program can be used for multiple processes but not more than one in any timestamp.

So, we have the process schedules and we want to find the number of wrapper programs to monitor them according to the given restrictions. As you are the leading programmer of this project, you are asked to find the minimum number of wrapper programs to monitor all the processes.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 50000). Each of the next n lines contains two integers si ti (1 ≤ si ≤ ti ≤ 109).

Output

For each case, print the case number and the minimum number of wrapper programs to monitor all the processes.

Sample Input

Output for Sample Input

2

2

1 3

3 5

4

1 10

10 20

11 21

3 5

Case 1: 2

Case 2: 2

Note

Dataset is huge, use faster I/O methods.


PROBLEM SETTER: JANE ALAM JAN
思路:离散化+线段树;
转换为求重复次数最多的点,因为重复处必须要分开,那么只要找到那个重复最多次数的点将这些段分成重复最多次数段即可。
  1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<set>
8 using namespace std;
9 typedef long long LL;
10 typedef struct pp
11 {
12 int x;
13 int y;
14 int id;
15 } ss;int maxx;
16 ss ans[50005];
17 int ak[200000];
18 int tree[200000*4];
19 void in(int n,int m,int l,int r,int k)
20 {
21 if(l>m||r<n)
22 {
23 return ;
24 }
25 else if(l<=n&&r>=m)
26 {
27 tree[k]+=1;
28 return ;
29 }
30 else
31 {
32 in(n,(n+m)/2,l,r,2*k+1);
33 in((n+m)/2+1,m,l,r,2*k+2);
34 }
35 }
36 void fang(int n,int m,int k)
37 {
38 if(n==m)
39 { if(tree[k]>maxx)
40 maxx=tree[k];
41 return ;
42 }
43 else
44 {
45 tree[2*k+1]+=tree[k];
46 tree[2*k+2]+=tree[k];
47 fang(n,(n+m)/2,2*k+1);
48 fang((n+m)/2+1,m,2*k+2);
49 }
50 }
51 int main(void)
52 {
53 int i,j,k;
54 scanf("%d",&k);
55 int s;
56 int n,m;
57 for(s=1; s<=k; s++)
58 { maxx=0;
59 scanf("%d",&n);
60 int vv=0;
61 for(i=0; i<n; i++)
62 {
63 scanf("%d %d",&ans[i].x,&ans[i].y);
64 ak[vv++]=ans[i].x;
65 ak[vv++]=ans[i].y;
66 }
67 sort(ak,ak+vv);
68 for(i=0; i<n; i++)
69 {
70 int l=0;
71 int r=vv-1;
72 int id=0;
73 while(l<=r)
74 {
75 int mid=(l+r)/2;
76 if(ak[mid]<=ans[i].x)
77 {
78 id=mid;
79 l=mid+1;
80 }
81 else r=mid-1;
82 }
83 ans[i].x=id;
84 l=0;
85 r=vv-1;
86 while(l<=r)
87 {
88 int mid=(l+r)/2;
89 if(ak[mid]<=ans[i].y)
90 {
91 id=mid;
92 l=mid+1;
93 }
94 else r=mid-1;
95 }
96 ans[i].y=id;
97 }
98 memset(tree,0,sizeof(tree));
99 for(i=0; i<n; i++)
100 {
101 in(0,200000,ans[i].x,ans[i].y,0);
102
103 }
104 fang(0,200000,0);
105 printf("Case %d: %d\n",s,maxx);
106 }
107 return 0;
108 }

最新文章

  1. .NET轻量级MVC框架:Nancy入门教程(一)——初识Nancy
  2. 纯css的防止图片撑破页面的代码图片会自动按比例缩小
  3. Data Base MongoDB 无法创建抽象类的问题,
  4. 按Right-BICEP要求的任务二的测试
  5. SQL带参数拼接
  6. Informatica 9.5.1 安装配置
  7. [转]深入浅出JSONP--解决ajax跨域问题
  8. C#关于通过反射PropertyType判读字符串类型方法
  9. 深入浅出mybatis之缓存机制
  10. Java中关于quartz定时任务时间设置
  11. day 7-6 多线程及开启方式
  12. MySQL数据库之触发器
  13. linux下shellcode提取常用到的命令
  14. Java平台标准版本
  15. Vue 部署单页应用,刷新页面 404/502 报错
  16. 【JS】#001 JS定义对象写法(原型、JSON方式)
  17. 目标反射回波检测算法及其FPGA实现 之三:平方、积分电路及算法的顶层实现
  18. Android Studio 导入系统 jar包
  19. [BZOJ4700]适者(CDQ分治+DP/李超线段树)
  20. 光驱在资源管理器显示黄色感叹号的解决方法BIOS内有 系统下没有

热门文章

  1. 构建LNMP+WordPress
  2. 【Redis集群原理专题】分析一下相关的Redis集群模式下的脑裂问题!
  3. 半天做完的数据报表,YonBuilder只要十几分钟,0代码开发
  4. JVM结构详解
  5. flink02------1.自定义source 2. StreamingSink 3 Time 4窗口 5 watermark
  6. STL学习笔记1
  7. Running shell commands by C++
  8. [项目总结]怎么获取TextView行数,为什么TextView获取行数为0?
  9. Android消除Toast延迟显示
  10. oracle 外部表查alter日志