ZJU 3787

简单的模拟。<img alt="微笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif" />
Access System

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define MAXN 20000 + 10
struct node{
    int h;
    int m;
    int s;
    int num;
}a[MAXN];

int ans[MAXN];
/*struct node1{
	int h1;
	int m1;
	int s1;
}ans[MAXN];*/

bool cmp(node a,node b){
    if(a.h == b.h){
        if(a.m == b.m){
            return a.s < b.s;
        }
        return a.m < b.m;
    }
    return a.h < b.h;
}

int main(){
    int T,n,l;
    int i;
    int count;
    int mark;
    //int flag;
    int sum;

    while(~scanf("%d",&T)){
        while(T--){
            memset(ans,0,sizeof(ans));
            sum = 0;
            //flag = 0;
            count = 1;
            mark = 0;
            scanf("%d%d",&n,&l);
            for(i=0;i<n;i++){
                scanf("%d:%d:%d",&a[i].h,&a[i].m,&a[i].s);
                a[i].num = i+1;
            }
            sort(a,a+n,cmp);
            ans[0] = a[0].num;
            sum = 1;
            for(i=1;i<n;){
                if(a[i].h == a[mark].h){
                    if(a[i].m == a[mark].m){
                        if(a[i].s-a[mark].s >= l){
                            //flag = 1;
                            mark = i;
							count++;
                            ans[sum++] = a[i].num;
                            continue;
                        }
                        else{
                            i++;
                            //count++;
                            continue;
                        }
                    }
                    else{
                        int mark1=a[i].s-a[mark].s;
                        int mark2=a[i].m-a[mark].m;
                        if(mark1+mark2*60 >= l){
                            mark = i;
							count++;
                            ans[sum++] = a[i].num;
                            continue;
                        }
                        else{
                            //count++;
                            i++;
                            continue;
                        }
                    }
                }
                else{
                    int mark3=a[i].s-a[mark].s;
                    int mark4=a[i].m-a[mark].m;
                    int mark5=a[i].h-a[mark].h;
                    if(mark3+mark4*60+mark5*3600 >= l){
                        mark = i;
						count++;
                        ans[sum++] = a[i].num;
                        continue;
                    }
                    else{
                        i++;
                        //count++;
                        continue;
                    }
                }
            }
			sort(ans,ans+sum);
            printf("%d\n",count);
            for(i=0;i<sum;i++){
                if(i != sum-1){
                    printf("%d ",ans[i]);
                }
                else{
                    printf("%d\n",ans[i]);
                }
            }
        }
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值