Access System(sort 排序~小贪心问题)
来源:互联网 发布:dw做淘宝全屏代码 编辑:程序博客网 时间:2024/05/04 07:18
Access System
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;}
- Access System(sort 排序~小贪心问题)
- hdu 1009 肥胖鼠 贪心(一) sort 排序函数
- day_3-acm贪心(sort结构体排序)
- 洛谷 1654 产品排序(sort) 背包DP+贪心
- ZOJ 3787Access System(排序)
- CodeForces597BRestaurant(sort+贪心)
- 【Sort】75. Sort Colors(计数排序、荷兰国旗问题)
- 【转】模糊排序问题(Fuzzy sort)
- 模糊排序问题(Fuzzy sort)
- 容器sort排序问题
- Sort排序问题
- Collections.sort排序小经典
- HDU5821 贪心,排序(+sort结构体排序,稳定性和不稳定性)
- NYOJ 236心急的C小加(排序贪心)
- NYOJ236. 心急的C小加(排序+贪心)
- 集合相等问题(java sort排序数组长度问题)
- sort(1,2,3)快速排序+贪心(nlongn):今年暑假不AC
- shell sort 希尔排序问题
- block,代理和通知的简单介绍--swift闭包
- 数据结构-Collection
- mybatis在xml文件中处理转义字符
- Unity Shaders and Effects Cookbook (4-1)(4-2)静态立方体贴图的创建与使用
- swustoj956约瑟夫问题的实现
- Access System(sort 排序~小贪心问题)
- 忘记Oracle数据库管理员密码的解决办法
- HDOJ(HDU) 1587 Flowers(水、、)
- 其他控件触发ddlb的selectionchanged事件及模糊查询
- Hibernate一对多映射配置
- Swift命名空间
- SnackBar的基本使用
- Android解析json数据
- 关于学习以及知识