DONALDO
Given below c/c++ code for donaldo spoj .
An easy question . Here you can use queue for solving the question . In queue start pushing time till difference b/w first and last element is less then given time I (in question ) . After that calculate the size of queue that will give you the number of girlfriend possible in that time interval. Now after that remove first element from the queue. and repeat this process till all time stamp are not consider .
For the case if there are more time stamp with same value then remove all element from queue at a time.
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&t); for(int test = 1 ; test<= t; test++){ int hh , mm , tt , I; int n; scanf("%d",&n); vector<long long > v; long long temp; char a; for(int i = 0 ; i < n ; i++){ scanf("%d%c%d%c%d",&hh,&a ,&mm,&a,&tt); temp = hh*3600 + mm*60 + tt; v.push_back(temp); } scanf("%d",&I); if(n==0){ printf("Case %d: 0\n",test); continue; } sort(v.begin() , v.end()); queue<long long> q; int j = 0 , len = -1; q.push(v[j]); while(j<n){ while(j< n && v[j] - q.front() < I){ j++; q.push(v[j]); } int size = q.size() - 1; len = max(len , size); int temp = q.front(); q.pop(); while(!q.empty() && temp == q.front()) q.pop(); } printf("Case %d: %d\n",test ,len); } }
No comments:
Post a Comment
Your comment is valuable to us