Sunday, 5 June 2016

Wooden Sticks (UVALive 2322, ZOJ 1025, HDU 1051, POJ 1065, SPOJ MSTICK, Regionals 2001 >> Asia - Taejon)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n;
    pair<int, int> pii[5002];
    bool vis[5002];
    string s;
    char ch;
    cin>>tc;
    while(tc--)
    {
        CLR(vis);
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>pii[i].first>>pii[i].second;
        sort(pii, pii+n);
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(!vis[i])
            {
                cnt++;
                vis[i]=true;
                int cur=i;
                for(int j=i+1;j<n;j++)
                    if(!vis[j])
                        if(pii[j].second>=pii[cur].second)
                        {
                            vis[j]=true;
                            cur=j;
                        }
            }

        }
        cout<< cnt <<"\n";
    }
return 0;
}

No comments:

Post a Comment