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 }

1301 - Monitoring Processes的更多相关文章

  1. Monitoring Processes with Supervisord

    If you're interested in more of this type of content, check out the Servers for Hackers eBook! As so ...

  2. 通过inotify监控linux文件系统变化

    http://www.mjmwired.net/kernel/Documentation/filesystems/inotify.txt http://www.ibm.com/developerwor ...

  3. The Best KPIs to Use in Your Company

    Here is a list of key performance indicators (KPIs) that should be used in contact centres, alongsid ...

  4. Apache CloudStack Features

    As a mature and turnkey Infrastructure-as-a-Service (IaaS) platform, Apache CloudStack has a compreh ...

  5. Zabbix二次开发_03api列表

    基于zabbix 3.0 https://www.zabbix.com/documentation/3.0/manual/api/reference Method reference This sec ...

  6. mysql的AB及读写和集群

    Mysql的AB及读写  第1章 Mysql的AB配置 1.1 master配置 1.2 slave配置 第2章 读写分离 2.1 安装mycat 2.2 启动mycat 2.3 登录mycat相关问 ...

  7. 基于MySQL+MHA+Haproxy部署高可用负载均衡集群

    一.MHA 概述 MHA(Master High Availability)是可以在MySQL上使用的一套高可用方案.所编写的语言为Perl 从名字上我们可以看到.MHA的目的就是为了维护Master ...

  8. Arch系统软件列表

    1. 安装统计 2. 安装列表 3. 安装说明 4. 作为依赖项的安装列表 5. 更正 mangaro使用减的方式安装系统.开箱即用的豪华版本,大部分人需要的都有了,同样包括个别用户不需要的,配置方面 ...

  9. 【线上测试之后的应用】基于MySQL+MHA+Haproxy构建高可用负载均衡数据库集群(详解)

    这里我们先介绍一下MHA是什么,其次就是它的应用与测试,同时为了大家呈现了数据备份案例,最后总结了使用情况以及注意事项和解决办法 一.MHA 概述 MHA(Master High Availabili ...

随机推荐

  1. 05 Windows安装python3.6.4+pycharm环境

    windows安装python3.6.4环境 使用微信扫码关注微信公众号,并回复:"Python工具包",免费获取下载链接! 一.卸载python环境 卸载以下软件: 二.安装py ...

  2. 【Redis】Sentinel 哨兵模式

    Sentinel(哨兵模式) 目录 Sentinel(哨兵模式) 哨兵模式的三个定时任务 Sentinel(哨兵)与Sentinel .主服务器.从服务器之间的连接 检测下线状态 选择领头 Senti ...

  3. java的缓冲流及使用Properties集合存取数据(遍历,store,load)

    缓冲流 概述 字节缓冲流:BufferedInputStream,BufferedOutputStream 字符缓冲流:BufferedReader,BufferedWriter 缓冲流原理 缓冲区是 ...

  4. 作为Java技术面试官,我如何深挖候选人的技能

    作为Java资深技术面试官,首先我感觉有必要讲解"面试官深挖问题"的动机,在了解动机的前提下,大家才能更好地准备面试.面试官为什么要在一个点上深挖?两大目的.   1 首先是通过深 ...

  5. adjust, administer

    adjust to just, exact. In measurement technology and metrology [度量衡学], calibration [校准] is the compa ...

  6. adverb

    An adverb is a word or an expression that modifies a verb, adjective, another adverb, determiner [限定 ...

  7. Spark(十)【RDD的读取和保存】

    目录 一.文件类型 1.Text文件 2.Json文件 3.对象文件 4.Sequence文件 二.文件系统 1. MySQL 2. Hbase 一.文件类型 1.Text文件 读写 读取 scala ...

  8. 大数据学习day13------第三阶段----scala01-----函数式编程。scala以及IDEA的安装,变量的定义,条件表达式,for循环(守卫模式,推导式,可变参数以及三种遍历方式),方法定义,数组以及集合(可变和非可变),数组中常用的方法

    具体见第三阶段scala-day01中的文档(scala编程基础---基础语法)  1. 函数式编程(https://www.cnblogs.com/wchukai/p/5651185.html): ...

  9. 100个Shell脚本—【脚本6】拷贝目录

    [脚本6]拷贝目录 编写shell脚本,把/root/目录下的所有目录(只需要一级)拷贝到/tmp/目录下: 一.脚本 #!/bin/bash cd /root list=(`ls`) for i i ...

  10. recyclerView DiffUtil使用

    DiffUtil是和RecyclerView一块用的,DiffUtil用来比较两个数据集,他的最大用处是在RecyclerView刷新时,不在无脑. 以前adapter.notifyDataSetCh ...