Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Wednesday, January 14, 2015

DONALDO-DONALDO

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);
    }
}