Access System(sort 排序~小贪心问题)

来源:互联网 发布:dw做淘宝全屏代码 编辑:程序博客网 时间:2024/05/04 07:18

Access System

Time Limit: 2000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name:Main
SubmitStatus

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) andL (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

32 112:30:0012:30:015 1517:00:0017:00:1517:00:0617:01:0017:00:143 512:00:0912:00:0512:00:00

Sample Output

21 231 2 422 3


#include<stdio.h>#include<algorithm>using namespace std;struct node{int j,k,l;int a,b,c,d,e,f;int num;}a[40000];void input(int i){int j,k,l;a[i].num=i;scanf("%d",&j);a[i].j=j;getchar();scanf("%d",&k);a[i].k=k;getchar();scanf("%d",&l);a[i].a=j/10;a[i].b=j%10;a[i].c=k/10;a[i].d=k%10;a[i].e=l/10;a[i].f=l%10;a[i].l=l;}bool cmp(struct node a,struct node b){if(a.a==b.a){if(a.b==b.b){if(a.c==b.c){if(a.d==b.d){if(a.e==b.e){if(a.f==b.f)return a.f<b.f;return a.f<b.f;}return a.e<b.e;}return a.d<b.d;}return a.c<b.c;}return a.b<b.b;}return a.a<b.a;}bool cmp1(int x,int y){return x<y;}int cha(struct node x,struct node y){int j,k,l,c;j=(x.j-y.j)*60*60;k=(x.k-y.k)*60;l=x.l-y.l;c=j+k+l;return c;}int main(){int T;scanf("%d",&T);while(T--){int n,m,f[40000],flag,sum,i;scanf("%d%d",&n,&m);for(i=1;i<=n;i++)input(i);sort(a+1,a+n+1,cmp);f[1]=a[1].num;flag=1;sum=1;for(i=2;i<=n;i++){if(cha(a[i],a[flag])>=m){f[++sum]=a[i].num;flag=i;}}printf("%d\n",sum);sort(f+1,f+sum+1,cmp1);for(i=1;i<=sum;i++){if(i==sum)printf("%d",f[i]);elseprintf("%d ",f[i]);}printf("\n");}return 0;}

0 0