Access System ZOJ - 3787

博客围绕Marjar大学宿舍门禁系统展开,该系统需学生用卡开门,门开启L秒。给定N个学生到达时间,这些学生非必要不刷卡,要求找出需刷卡的学生。输入包含案例数、学生数和开门时长等,输出需刷卡学生数量及位序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

For security issues, Marjar University has an access control system for each dormitory building.The system requires the students to use their personal identification cards to open the gate if they want to enter the building.

The gate will then remain unlocked for L seconds. For example L = 15, if a student came to the dormitory at 17:00:00 (in the format of HH:MM:SS) and used his card to open the gate. Any other students who come to the dormitory between [17:00:00, 17:00:15) can enter the building without authentication. If there is another student comes to the dorm at 17:00:15 or later, he must take out his card to unlock the gate again.

There are N students need to enter the dormitory. You are given the time they come to the gate. These lazy students will not use their cards unless necessary. Please find out the students who need to do so.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains two integers N (1 <= N <= 20000) and L (1 <= L <= 3600). The next N lines, each line is a unique time between [00:00:00, 24:00:00) on the same day.

Output

For each test case, output two lines. The first line is the number of students who need to use the card to open the gate. The second line the the index (1-based) of these students in ascending order, separated by a space.

Sample Input

3
2 1
12:30:00
12:30:01
5 15
17:00:00
17:00:15
17:00:06
17:01:00
17:00:14
3 5
12:00:09
12:00:05
12:00:00

Sample Output

2
1 2
3
1 2 4
2
2 3

题意: T:案例数,输入n,m。n代表人数,m代表刷一次卡,门开的时间长度。输出:最少有多少人需要刷卡,以及刷卡人的位序。


#include<iostream>
#include<cstring>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
const int maxn = 20100;
int mapp2[maxn];
int n, m, k, j;

//结构体中,a、b、c分别代表每个同学开门的时、分、秒,sum代表所有时间换算成秒的结果;
struct node
{
    int a, b, c;
    int sum;
    int d;
}mapp1[maxn];

//总秒数按升序排序;
bool cmp(node x, node y)
{
    return x.sum<y.sum;
}
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        k = 2;
        j = 1;
        scanf("%d%d", &n, &m);
        for(int i=1; i<=n; i++)
        {
            scanf("%d:%d:%d", &mapp1[i].a, &mapp1[i].b, &mapp1[i].c);
            mapp1[i].d = i;//标记每个同学的位序;
            mapp1[i].sum = mapp1[i].a*3600+mapp1[i].b*60+mapp1[i].c;//换算为总秒数;
        }
        sort(mapp1+1, mapp1+1+n, cmp);//按照秒数多少做升序排序;
        mapp2[1] = mapp1[1].d;//在排完序后第一个同学一定是需要刷卡的,记录其位序;
        for(int i=1; i<n; i++)
        {
            //如果后一个同学的秒数比前一个刷卡的同学的秒数大于等于m,那么后一个同学的则需要刷卡,记录其位序,并更新刷卡同学的秒数;
            if((mapp1[i+1].sum-mapp1[j].sum)>=m)
            {
                mapp2[k] = mapp1[i+1].d;
                k++;
                j = i+1;
            }
        }
        k = k-1;
        //对位序数进行升序排序,并输出需要刷卡人数和刷卡同学的位序;
        sort(mapp2+1, mapp2+1+k);
        printf("%d\n", k);
        for(int i=1; i<=k; i++)
        {
            if(i!=k)
                printf("%d ", mapp2[i]);
            else
                printf("%d\n", mapp2[i]);
        }
    }
    return 0;
}

 

内容概要:本文深入探讨了Kotlin语言在函数式编程和跨平台开发方面的特性和优势,结合详细的代码案例,展示了Kotlin的核心技巧和应用场景。文章首先介绍了高阶函数和Lambda表达式的使用,解释了它们如何简化集合操作和回调函数处理。接着,详细讲解了Kotlin Multiplatform(KMP)的实现方式,包括共享模块的创建和平台特定模块的配置,展示了如何通过共享业务逻辑代码提高开发效率。最后,文章总结了Kotlin在Android开发、跨平台移动开发、后端开发和Web开发中的应用场景,并展望了其未来发展趋势,指出Kotlin将继续在函数式编程和跨平台开发领域不断完善和发展。; 适合人群:对函数式编程和跨平台开发感兴趣的开发者,尤其是有一定编程基础的Kotlin初学者和中级开发者。; 使用场景及目标:①理解Kotlin中高阶函数和Lambda表达式的使用方法及其在实际开发中的应用场景;②掌握Kotlin Multiplatform的实现方式,能够在多个平台上共享业务逻辑代码,提高开发效率;③了解Kotlin在不同开发领域的应用场景,为选择合适的技术栈提供参考。; 其他说明:本文不仅提供了理论知识,还结合了大量代码案例,帮助读者更好地理解和实践Kotlin的函数式编程特性和跨平台开发能力。建议读者在学习过程中动手实践代码案例,以加深理解和掌握。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值