zoj-3721(贪心)

In Zhejiang University, there are N different courses labeled from 1 toN. 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 andt 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 theith 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

题目题意:题目会给我们n组时间区间(左闭右开),表示有考试,题目说,考试可以同一天,为了尽可能的减少考试天数,求最小的考试天数(能够分配所有的考试)

题目分析:为了使天数最小,也就是让尽可能多的考试,分配在同一天,我们按照考试的开始时间从小到大排序,开始时间相同的,按照时间结束短的优先,然后从第二开始,与一个比较,如果在范围内,就可以在同一天,而且(注意:缩小范围) ,也就是说,能够在同一天考试,那么就要保证所有的考试的时间区间有公共子区间,这里错了很多遍,

所以要缩小范围。

为了让方便理解(其实是我自己表达的不好),我打个比方:

考试1为 [1 ,5) 与考试二[2,6) 可以在同一天举行,那么他们和在一起的新区间为[2,5),考试三为[3,4),也有公共区间,那么它们三和在一起,新区间为[3,4),考试四为[4,5)它就不能在一起考了。

所以我们就要不断更新公共区间,之到没有了,就在下一天举行。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int maxn=1e5+10;
struct note
{
    int l, r;
    int flag;//考试的序号
}p[maxn];
vector<int> vec[maxn];//保存每一天的考试
bool cmp(struct note a,struct note b)//排序规则
{
    if (a.l==b.l)
        return a.r<b.r;
    return a.l<b.l;
}

int main()
{
    int n;
    while (scanf("%d",&n)!=EOF) {
        for (int i=1;i<=n;i++) {
            scanf("%d%d",&p[i].l,&p[i].r);
            p[i].flag=i;
        }
        sort (p+1,p+n+1,cmp);
        int res=1;
        vec[res].push_back(p[1].flag);//把第一天丢进出
        int maxl=p[1].l,maxr=p[1].r;
        for (int i=2;i<=n;i++) {
            if (p[i].l<maxr) {//在第一天范围内,
                vec[res].push_back(p[i].flag);
                if (p[i].r<maxr)//更新区间范围
                    maxr=p[i].r;
            }
            else {
                maxl=p[i].l;//不在,另起一个区间,新的一天
                maxr=p[i].r;
                res++;//天数++
                vec[res].push_back(p[i].flag);
            }
        }
        for (int i=1;i<=res;i++)
            sort(vec[i].begin(),vec[i].end());//保证答案,升序
        printf("%d\n",res);
        for (int i=1;i<=res;i++) {
            for (int j=0;j<vec[i].size();j++) {
                printf("%d",vec[i][j]);
                if (j==vec[i].size()-1) printf("\n");
                else printf(" ");
            }
            vec[i].clear();
        }
        printf("\n");
    }
    return 0;
}




















































内容概要:本文深入解析了扣子COZE AI编程及其详细应用代码案例,旨在帮助读者理解新一代低门槛智能体开发范式。文章从五个维度展开:关键概念、核心技巧、典型应用场景、详细代码案例分析以及未来发展趋势。首先介绍了扣子COZE的核心概念,如Bot、Workflow、Plugin、Memory和Knowledge。接着分享了意图识别、函数调用链、动态Prompt、渐进式发布及监控可观测等核心技巧。然后列举了企业内部智能客服、电商导购助手、教育领域AI助教和金融行业合规质检等应用场景。最后,通过构建“会议纪要智能助手”的详细代码案例,展示了从需求描述、技术方案、Workflow节点拆解到调试与上线的全过程,并展望了多智能体协作、本地私有部署、Agent2Agent协议、边缘计算插件和实时RAG等未来发展方向。; 适合人群:对AI编程感兴趣的开发者,尤其是希望快速落地AI产品的技术人员。; 使用场景及目标:①学习如何使用扣子COZE构建生产级智能体;②掌握智能体实例、自动化流程、扩展能力和知识库的使用方法;③通过实际案例理解如何实现会议纪要智能助手的功能,包括触发器设置、下载节点、LLM节点Prompt设计、Code节点处理和邮件节点配置。; 阅读建议:本文不仅提供了理论知识,还包含了详细的代码案例,建议读者结合实际业务需求进行实践,逐步掌握扣子COZE的各项功能,并关注其未来的发展趋势。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值