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. 整数v,从高位到低位,取c位数,得到最大数 (其中:v>=10^c)

    题目如上,例子v=22312324,c=3,求得最大数为334. 用自己的想法实现了一遍,如果你有更好的方法的话,欢迎不吝赐教. 我的思路是,先将整数v按位存入一个数组,数组低位为整数高位,如num[ ...

  2. Digital Roots(hdoj1013)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  3. STL初步

    1.stackstack 模板类的定义在<stack>头文件中.stack 模板类需要两个模板参数,一个是元素类型,一个容器类型,但只有元素类型是必要的,在不指定容器类型时,默认的容器类型 ...

  4. [python] 如何用python操作Excel

    直接上代码: from openpyxl import Workbook from openpyxl.cell import get_column_letter wb = Workbook() des ...

  5. activity 的返回按钮

    http://www.2cto.com/kf/201210/160251.html 连续点击两次程序就退出程序,这是一个很有趣的程序功能,下来介绍一下我的实现方式(欢迎大家拍砖指点):   1.在Ac ...

  6. Inno Setup 创建站点,创建虚拟目录

    原文 http://hi.baidu.com/0531_sunmiles/item/ce22554ab7d33d0be9350477 下面的这段代码是用Inno Setup 做安装包的时候创建IIS新 ...

  7. SQL表名,应该用复数还是单数

    用单数形式更佳,理由如下: 1.概念直观. 你有一个袋子,里面有好多个苹果,你会说这是个苹果袋.但无论里面有0,1,百万个苹果,它依然是个袋子.表也是如此,表明需要描述清楚,表里面包含的对象,而非有多 ...

  8. cocos2dx lua 学习笔记(一)

    macosx 安装 lua curl -R -O http://www.lua.org/ftp/lua-5.1.4.tar.gz tar zxf lua-5.1.4.tar.gz cd lua-5.1 ...

  9. A Game with Colored Balls

    题目链接 题意: 给一个长度为n的字符串,每次删除字母同样切连续的串,假设有多个,删除最左边的.最长的串.每次删除输出串的字母,每一个字母的下标(1-n) N (1 ≤ N ≤ 106),串仅仅包含r ...

  10. Malloc碎碎念

    (以前为给同学分享写的点东西,很基础.)现在的比赛中堆溢出非常常见,对于glibc下malloc的理解也要深入一些. malloc_chunk的对齐属性 在glibc中,malloc_chunk以 2 ...