Knobody

ONE KING

Jun 13th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define dbg(i,j) cout<<"I am "<<i<<" = "<<endl<<j<<endl;
  3. #define dbr(name,a) cout<<name<<endl;for(auto x:a)cout<<x<<" ";cout<<endl;
  4. #define DBR(name,a) cout<<name<<endl;for(auto x:a){ for(auto y:x)cout<<y<<" ";cout<<endl;}
  5. #define dbmp(name,a) cout<<name<<endl;for(auto x:a){ cout<<x.first<<"\t"<<x.second<<endl;}
  6. #define dbp(name,a) cout<<name<<endl;cout<<a.first<<"\t"<<a.second<<endl;
  7. #define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  8. using namespace std;
  9.  
  10. typedef long long int big;
  11.  
  12. typedef  long double fig;
  13.  
  14. big mx(vector<big>& v,big i,big j){
  15.     big m=i;
  16.     for(big z=i+1;z<=j;z++){
  17.         if(v[z]>v[m]){
  18.             m=z;
  19.         }
  20.     }
  21.     return m;
  22. }
  23.  
  24. big mn(vector<big>& v,big i,big j){
  25.     big m=i;
  26.     for(big z=i+1;z<=j;z++){
  27.         if(v[z]>v[m]){
  28.             m=z;
  29.         }
  30.     }
  31.     return m;
  32. }
  33.  
  34. bool Find_Intersection(pair<big,big>& p1,pair<big,big>& p2){
  35.     if(p2.first<=p1.second){
  36.         p1.first=p2.first;
  37.         p1.second=min(p1.second,p2.second);
  38.         return true;
  39.     }
  40.     else{
  41.         return false;
  42.     }
  43. }
  44.  
  45. int main(){
  46.     big test;
  47.     cin>>test;
  48.     while(test--){
  49.         big n;
  50.         cin>>n;
  51.         vector<pair<big,big>> pairs;
  52.         for(big i=0;i<n;i++){
  53.             big a;
  54.             big b;
  55.             cin>>a>>b;
  56.             pairs.push_back(make_pair(a,b));
  57.         }
  58.         sort(pairs.begin(),pairs.end());
  59.         big count=1;
  60.         pair<big,big> test=pairs[0];
  61.         for(big j=1;j<n;j++){
  62.             if(Find_Intersection(test,pairs[j])){
  63.                 ;  
  64.             }
  65.             else{
  66.                 count++;
  67.                 test=pairs[j];
  68.             }
  69.         }
  70.         cout<<count<<endl;     
  71.     }
  72.     return 0;
  73. }
Add Comment
Please, Sign In to add comment