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
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3787 题意:题目大概意思有多组测试数据,每组给出个两行数据,第一行两个数N、L,分别代表N个时间,和每隔L时间才能刷卡进去。第二行给出N个时间,问最多有多少个时间去刷卡能进入,并从小到大将能刷卡进入的时间位置输出来。 思路:把所有时间数据存入结构体数组中,然后把时间都用秒的形式存入结构体中,并把数据所处的位置存入结构体中。对时间秒进行结构体排序。用另一个数组记录所有满做条件的时间的位置。并记录个数。 */ #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct node{ int a; int b; int c; int d; // 标记位置 int e; // 用秒记录 }stu[20100]; bool cmp(node x,node y) // 升序排序 { return x.e<y.e; } int main() { int t,n,a,i,j,k,b[20100]; scanf("%d",&t); while(t--) { k=1;j=0; scanf("%d%d",&n,&a); for(i=0;i<n;i++) { scanf("%d:%d:%d",&stu[i].a,&stu[i].b,&stu[i].c); stu[i].d=i+1; //记录位置 stu[i].e=stu[i].a*3600+stu[i].b*60+stu[i].c; // 把时间用秒记录 } sort(stu,stu+n,cmp); b[0]=stu[0].d; for(i=0;i<n-1;i++) { if((stu[i+1].e-stu[j].e)>=a) { b[k]=stu[i+1].d; // 把位置存入另一个数组中 k++; // 记录能刷卡进入时间的个数 j=i+1; // 记录上一个满足条件时间的位置 } } sort(b,b+k); // 对位置数组排序 printf("%d\n",k); for(i=0;i<k;i++) { if(i!=k-1) printf("%d ",b[i]); else printf("%d\n",b[i]); } } return 0; }