Access System

来源:互联网 发布:mac单机版游戏下载 编辑:程序博客网 时间:2024/06/06 18:23

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;//timesStudent* student;//array of studentssize_t stu_size;//the number of studentsunsigned int interval;//the time between open and closeunsigned int close;//time of close the doorunsigned 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 inputfor (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 inputstd::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_cardclose = 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 judgestd::sort(list_of_need_card.begin(),list_of_need_card.end());//sort the list_of_need_card to output//start outputprintf("%u\n", list_of_need_card.size());//the first line,sizeprintf("%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 outputdelete[] student;}return EXIT_SUCCESS;}


0 0
原创粉丝点击