Access System

Access System

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:70            测试通过:15

描述

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.

输入

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.

输出

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.

样例输入

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

样例输出

2
1 2
3
1 2 4
2
2 3

#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>

typedef struct{
	unsigned int time;//the time when this student enter,(second)
	unsigned int number;
}Student;

bool time_compare(Student a, Student b){
	return a.time < b.time;
}

int main(void){
	unsigned int times;//times
	Student* student;//array of students
	size_t stu_size;//the number of students
	unsigned int interval;//the time between open and close
	unsigned int close;//time of close the door
	unsigned int hour, minute, second;
	std::vector<unsigned int> list_of_need_card;
	scanf("%u", &times);
	while (times--){
		scanf("%u%u", &stu_size, &interval);
		student = new Student[stu_size];
		list_of_need_card.clear();
		//start input
		for (size_t stu_index(0); stu_index != stu_size; ++stu_index){
			scanf("%u:%u:%u", &hour, &minute, &second);
			student[stu_index].time = hour*3600 + minute*60 + second;
			student[stu_index].number = stu_index + 1;
		}
		//end of input
		std::sort(student, student + stu_size, time_compare);//sort the student list according to the time
		//judge each student need card or not,if need,put the number in list_of_need_card
		close = student[0].time + interval;
		list_of_need_card.push_back(student[0].number);
		for (size_t stu_index(1); stu_index != stu_size; ++stu_index){
			if (student[stu_index].time >= close){
				list_of_need_card.push_back(student[stu_index].number);
				close = student[stu_index].time + interval;
			}
		}
		//end of judge
		std::sort(list_of_need_card.begin(),list_of_need_card.end());//sort the list_of_need_card to output
		//start output
		printf("%u\n", list_of_need_card.size());//the first line,size
		printf("%u", list_of_need_card[0]);
		for (std::vector<unsigned int>::iterator stu_iterator(list_of_need_card.begin() + 1); 
			stu_iterator != list_of_need_card.end(); ++stu_iterator)
		{
			printf(" %u", *stu_iterator);
		}
		printf("\n");
		//end of output
		delete[] student;
	}
	return EXIT_SUCCESS;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值