ZOJ 3787 Access System

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5274

题面:


Access System

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

题意:

   公寓门禁问题,如果一个人开了门,那么他下一个在L时间内,进入的不需要刷门禁。问哪些人需要刷门禁。

   比较麻烦的是,要先排个序,还要保存他们原先的序号,还有排完后,还要从小到大输出哪些人需要刷门禁。

   用了C++输入,还用了这么多STL,没超时,也是挺6的。


代码:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct combine
{
  int No;
  string s;	
};
bool cmp(combine a,combine b)
{
	return a.s<b.s;
}
int main()
{
    int t,n,l,cnt,curtime,tmptime;
    string tmp;
    cin>>t;
    while(t--)
    { 
	  cnt=1;
      cin>>n>>l;
   	  vector <combine> store;
   	  vector <int> ans;
   	  combine temp;
   	  for(int i=1;i<=n;i++)
   	  {
  	   	cin>>temp.s;
  	   	temp.No=i;
  	   	store.push_back(temp);
      }
      sort(store.begin(),store.end(),cmp);
      curtime=((store[0].s[0]-'0')*10+(store[0].s[1]-'0'))*3600+((store[0].s[3]-'0')*10+(store[0].s[4]-'0'))*60+(store[0].s[6]-'0')*10+store[0].s[7]-'0';
      ans.push_back(store[0].No);
	  for(int i=1;i<n;i++)
	  {
  		tmptime=((store[i].s[0]-'0')*10+(store[i].s[1]-'0'))*3600+((store[i].s[3]-'0')*10+(store[i].s[4]-'0'))*60+(store[i].s[6]-'0')*10+store[i].s[7]-'0';
  		if(tmptime>=(curtime+l))
  		{
		  curtime=tmptime;
		  ans.push_back(store[i].No);
		  cnt++; 	
	    }
  	  }
  	    sort(ans.begin(),ans.end());
		cout<<cnt<<endl;
		cout<<ans[0];
		for(int i=1;i<ans.size();i++)
		cout<<" "<<ans[i];
		cout<<endl;	
    }
	return 0;
}



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。