Final Exam Arrangement(ZOJ)
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)的更多相关文章
- zoj 3721 Final Exam Arrangement【贪心】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 来源:http://acm.hust.edu.cn/vjudg ...
- Java中static、final、static final的区别(转)+transient
说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...
- Drools 7.4.1.Final参考手册(八) 规则语言参考
规则语言参考 概述 Drools有一个“本地”的规则语言.这种格式在标点符号上非常轻,并且通过“扩展器”支持自然语言和领域特定的语言,使语言能够变形到您的问题领域.本章主要与本机规则格式一致.用于表示 ...
- Drools 7.4.1.Final参考手册(六) 用户手册
用户手册 基础 无状态的知识Session Drools规则引擎拥有大量的用例和功能,我们要如何开始?你无须担心,这些复杂性是分层的,你可以用简单的用例来逐步入门. 无状态Session,无须使用推理 ...
- public,protected,private,static,final的区别(转载)
1.类 (1)在java中有public.protected.private三种显示的修饰符用于控制可见性,package不是显示的修饰符,它是隐含的,即如果在类.变量等前没加显示的可见性修饰符,那它 ...
- 为什么接口要规定成员变量必须是public static final的呢?(转)
在interface里面的变量默认都是public static final 的.所以可以直接省略修饰符: String param="ssm"://变量需要初始化 为什么接口要规 ...
- Java中static、final、static final的区别(转)
说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...
- UVa 1638 - Pole Arrangement(dp)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- final static 修饰(转载)
static修饰符 static修饰符能够与属性.方法和内部类一起使用,表示静态的.类中的静态变量和静态方法能够与类名一起使用,不需要创建一个类的对象来访问该类的静态成员,所以,stat ...
随机推荐
- MYSQL create database 和 create table 做了一些什么!
create database Studio; 这样就可以创建一个数据库了.他包涵一些什么呢? 可以看到它创建了一个文件夹,下面我们进去看一下它里面有一些什么东西. 还是先建一张表再进去吧,运行一下这 ...
- 将一段含有0的字符数组赋给string
string有个成员函数,assign() 可以这样: string str; str.assign(temp, sizeof(temp));
- thinkphp这样玩关联查询(实例教会你)
thinkphp实例,内连接实现多表中同时查找,并存在了一个数组中,返回到模板中,模板中volist遍历即可使用多表中的字段 $row=M()->query("select realn ...
- Android ListView A~Z快速索引(改进版)
上一篇文章虽然实现了ListView 快速索引的效果,但是有一个小小的Bug.这个Bug我在前面也说了,这篇文章就来解决这个Bug. 我研究的时候发现只要showBg值为true,中间的字母就显示,而 ...
- Photoshop技能167个经典的Photoshop技巧大全
Photoshop技能167个经典的Photoshop技巧大全 学PS基础:Photoshop 技能167个 经典的Photoshop技巧大全,如果你是初级阶段的水平,熟读此文并掌握,马上进阶为中级 ...
- wordpress All in one Seo
原文地址:http://www.7adesign.com/155.html WordPress插件All-in-one-seo-pack详细设置: I enjoy this plugin and ha ...
- 【hihocoder 1258 Osu! Master】
2015北京区域赛现场赛签到题. 题面:http://media.hihocoder.com/contests/icpcbeijing2015/problems.pdf OJ链接:http://hih ...
- java中如何将char数组转化为String
1.直接在构造String时建立. char data[] = {'s', 'g', 'k'}; String str = new String(data); 2.String有方法可以直接转换. S ...
- system函数遇到的问题 - 程序死掉
system函数遇到的问题 解决方案见最下边 http://blog.csdn.net/yangzhenzhen/article/details/51505176 这几天调程序(嵌入式linux),发 ...
- Unity 之 Redux 模式(第一篇)—— 人物移动
作者:软件猫 日期:2016年12月6日 转载请注明出处:http://www.cnblogs.com/softcat/p/6135195.html 在朋友的怂恿下,终于开始学 Unity 了,于是有 ...