ZOJ 3787 Access System


テーマリンク:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5274
タイトル:
Access System
Time Limit: 2 Seconds     
メモリLimit: 65536 KB
For security ises Marjar University has an access control system for each dormitory building.The system requires the students to use their person dentificards to open the gate if the 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(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 compes to the dorm at 17:00 or later,he must take out hit to unlock the gate.
The re are N students need to nter the dormitory.You are given the time the y come to the gate.The lazy students will not use their cards uncessary.Please find out the students who need to do so.
Input
The re 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、24:00]on the same day.
Output
For each test case,output two line.The first line is the number of students who need to use the card to open the gate.The second line the index(1-based)of the students in ascendorder,pated sprace
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を使って、タイムアウトしていません。
コード:
#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;
}