ZOJ - 3787
#include<bits/stdc++.h>
using namespace std;
struct node
{
int h,m,s,order,flag;
} a[20005];
bool cmp(node x,node y)
{
if(x.h==y.h&&x.m==y.m)
return x.s<y.s;
else if(x.h==y.h)
return x.m<y.m;
else
return x.h<y.h;
}
int total,Time,sum,b[20004];
bool calculate(node &temp1,node &temp2)
{
int ans=(temp1.h-temp2.h)*3600+(temp1.m-temp2.m)*60+(temp1.s-temp2.s);
if(ans<Time)
{
temp1.flag=0;
return false;
}
return true;
}
int main()
{
int t;
char str;
cin>>t;
while(t--)
{
sum=1;
cin>>total>>Time;
for(int i=0; i<total; i++)
{
cin>>a[i].h>>str>>a[i].m>>str>>a[i].s;
a[i].order=i+1;
a[i].flag=1;
}
sort(a,a+total,cmp);
b[sum]=a[0].order;
for(int i=1; i<total; i++)
for(int j=i-1; j>=0; j--)
if(a[j].flag==1)
{
if(calculate(a[i],a[j]))
b[++sum]=a[i].order;
break;
}
cout<<sum<<endl;
sort(b+1,b+sum+1);
for(int j=1; j<sum; j++)
cout<<b[j]<<" ";
cout<<b[sum]<<endl;
}
return 0;
}