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;
}