In Zhejiang University, there are N different courses labeled from 1 to N. Each course has its own time slot during the week. We can represent the time slot of a course by an left-closed right-open interval [s, t).

Now we are going to arrange the final exam time of all the courses.

The final exam period will contain multiple days. In each day, multiple final exams will be held simultaneously. If two courses' time slots are not overlapped, there may be students who are attending both of them, so we cannot arrange their final exams at the same day.

Now you're to arrange the final exam period, to make the total days as small as possible.

Input

There are multiple test cases separated by blank lines.

For each ease, the 1st line contains one integer N(1<=N<=100000).

Then N lines, the i+1th line contains s and t of the interval [s, t) for the ith course.(0<=s<t<=231-1)

There is a blank line after each test case.

Output

For each case, the 1st line contains the days P in the shortest final exam period.

Next P lines, the i+1th line contains the numbers of courses whose final exam is arranged on the ith day separated by one space.

Output a blank line after each test case.

Sample Input

4
0 1
1 2
2 3
3 4 4
0 2
1 3
2 4
3 5 4
0 4
1 5
2 4
3 6

Sample Output

4
1
2
3
4 2
1 2
3 4 1
1 2 3 4
 #include <stdio.h>
#define N 100005
#include <algorithm>
using namespace std; struct node
{
int a,b,num;
} po[N];
int out[*N+];
int cmp(node x,node y)
{
if(x.a==y.a) return x.b>y.b;
return x.a<y.a;
}
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<n; i++)
{
scanf("%d%d",&po[i].a,&po[i].b);
po[i].num=i;
}
sort(po,po+n,cmp);
int k,ans=,c=;
for(i=; i<n; )
{
k=po[i].b;
for(j=i; ; j++)
{
if(po[j].a>=k)
{
i=j;
ans++;
out[c++]=-;
break;
}
else
{
out[c++]=po[j].num;
if(po[j].b<k) k=po[j].b;
}
if(j==n)
{
i=n;
break;
}
}
}
printf("%d\n",ans+);
for(i=; i<c-; i++)
{
if(out[i]==-) puts("");
else
{
if(i && out[i-]!=-) putchar(' ');
printf("%d",out[i]+);
}
}
puts("\n");
}
return ;
}

贪心

Final Exam Arrangement(ZOJ)的更多相关文章

  1. zoj 3721 Final Exam Arrangement【贪心】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 来源:http://acm.hust.edu.cn/vjudg ...

  2. Java中static、final、static final的区别(转)+transient

    说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...

  3. Drools 7.4.1.Final参考手册(八) 规则语言参考

    规则语言参考 概述 Drools有一个“本地”的规则语言.这种格式在标点符号上非常轻,并且通过“扩展器”支持自然语言和领域特定的语言,使语言能够变形到您的问题领域.本章主要与本机规则格式一致.用于表示 ...

  4. Drools 7.4.1.Final参考手册(六) 用户手册

    用户手册 基础 无状态的知识Session Drools规则引擎拥有大量的用例和功能,我们要如何开始?你无须担心,这些复杂性是分层的,你可以用简单的用例来逐步入门. 无状态Session,无须使用推理 ...

  5. public,protected,private,static,final的区别(转载)

    1.类 (1)在java中有public.protected.private三种显示的修饰符用于控制可见性,package不是显示的修饰符,它是隐含的,即如果在类.变量等前没加显示的可见性修饰符,那它 ...

  6. 为什么接口要规定成员变量必须是public static final的呢?(转)

    在interface里面的变量默认都是public static final 的.所以可以直接省略修饰符: String param="ssm"://变量需要初始化 为什么接口要规 ...

  7. Java中static、final、static final的区别(转)

    说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...

  8. UVa 1638 - Pole Arrangement(dp)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. final static 修饰(转载)

    static修饰符        static修饰符能够与属性.方法和内部类一起使用,表示静态的.类中的静态变量和静态方法能够与类名一起使用,不需要创建一个类的对象来访问该类的静态成员,所以,stat ...

随机推荐

  1. python笔记之Cmd模块

    python笔记之Cmd模块 Cmd类型提供了一个创建命令行解析器的框架,默认情况下,它使用readline来进行交互式操作.命令行编辑和命令完成. 使用cmd创建的命令行解释器循环读取输入的所有行并 ...

  2. 独木舟上的旅行--nyoj题目71

    独木舟上的旅行 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别.一条独木舟最多只能乘坐两个人,且乘客 ...

  3. Nginx 教程的连载计划

    下面以教程系列为单位,列举出了已经发表和计划发表的连载教程: Nginx 新手起步 Nginx 是如何匹配 URI 的 Nginx 变量漫谈 Nginx 配置指令的执行顺序 Nginx 的 if 是邪 ...

  4. python学习day12

    目录 html结构与标签 css样式   html结构之head <head> 标签用于定义文档的头部,它是所有头部元素的容器.<head> 中的元素可以引用脚本.指示浏览器在 ...

  5. Inno Setup:获取isl中的多国语言字串

    原文 http://zwkufo.blog.163.com/blog/static/25882512010101041626803/?suggestedreading&wumii 用InnoS ...

  6. 让app在ios6上具有ios7的扁平效果

    使用cocoapods在工程中加入UI7Kit,关于UI7Kit请自行google. 加入到工程 如果没安装cocoapods,则安装.(http://www.cocoapods.org) 安装方法: ...

  7. flume-采集报错

    h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...

  8. mybatis中使用log4j

    Mybatis默认使用有slf4j,所以必须加入下面的依赖,否则可能出现日志无法打印sql或者无法打印resultset. <dependency> <groupId>org. ...

  9. javascript 兼容各个浏览器的事件

  10. Silverlight学习(四) domainservice动态多条件查询

    上次讲了silverlight+MVVN+EF的简单框架,能够实现简单的数据CURD,但是多条件动态的查询一直没有实现.在网上查阅了很多资料,发现自己走了很多误区,代码很难调试正确. 这次的查询是基于 ...