HDOJ 2037

  1 #include<iostream>
  2 using namespace std;
  3 
  4 #include<vector>
  5 #include<math.h>
  6 #include<iomanip>
  7 #include<string.h>
  8 
  9 void swap(int &a,int &b)
 10 {
 11         int c = a;
 12         a = b;
 13         b = c;
 14 }
 15 
 16 int partition(vector<int> &vs,vector<int> &ve,int start,int end)
 17 {
 18         int a = vs[start];
 19         int b = ve[start];
 20         while(start < end)
 21         {
 22                 while(start < end && vs[end] >= a) --end;
 23                 if(start < end)
 24                 {
 25                         vs[start] = vs[end];
 26                         ve[start] = ve[end];
 27                 }
 28                 while(start < end && vs[start] <= a) ++start;
 29                 if(start < end)
 30                 {
 31                         vs[end] = vs[start];
 32                         ve[end] = ve[start];
 33                 }
 34         }
 35         vs[start] = a;
 36         ve[start] = b;
 37         return start;
 38 }
 39 
 40 void quickSort(vector<int> &vs,vector<int> &ve,int start,int end)
 41 {
 42         if(start < end)
 43         {
 44                 int pos = partition(vs,ve,start,end);
 45                 quickSort(vs,ve,start,pos-1);
 46                 quickSort(vs,ve,pos+1,end);
 47         }
 48 }
 49 
 50 int max(int count[],int start,int end)
 51 {
 52         int c = count[start];
 53         for(int i = start+1;i < end;i++)
 54         {
 55                 if(c < count[i]) c = count[i];
 56         }
 57         return c;
 58 }
 59 
 60 int findFirst(vector<int> vs,int a,int end)
 61 {
 62         int i = 0;
 63         while(vs[i] < a && i <= end) i++;
 64         if(i > end) return -1;
 65         return i;
 66 }
 67 
 68 int main()
 69 {
 70         int n,s,e,c,maxcount;
 71         while(cin>>n && n != 0)
 72         {
 73                 c = 0;
 74                 int count[n],i;
 75                 memset(count,0,sizeof(int)*n);
 76                 vector<int> vs,ve;
 77                 for(i = 0;i < n;i++)
 78                 {
 79                         cin>>s>>e;
 80                         vs.push_back(s);
 81                         ve.push_back(e);
 82                 }
 83                 quickSort(vs,ve,0,vs.size()-1);
 84                 for(i = 1;i < vs.size();)
 85                 {
 86                         while(vs[i] == vs[i-1])
 87                         {
 88                                 ++c;
 89                                 ++i;
 90                         }
 91                         quickSort(ve,vs,i-c-1,i-1);
 92                         c = 0;
 93                         ++i;
 94                 }
 95                 i = vs.size()-1;
 96                 while(vs[i] == vs[i-1])
 97                 {
 98                         count[i] = 1;
 99                         --i;
100                 }
101                 count[i] = 1;
102                 --i;
103                 maxcount = 1;
104                 for(;i >= 0;--i)
105                 {
106                         int start = findFirst(vs,ve[i],vs.size()-1);
107                         if(start == -1)
108                         {
109                                 count[i] = 1;
110                                 continue;
111                         }
112                         count[i] = 1+max(count,start,vs.size()-1);
113                         if(maxcount < count[i]) maxcount = count[i];
114                 }
115 
116                 cout<<maxcount<<endl;
117         }
118 
119         return 0;
120 }

 

转载于:https://www.cnblogs.com/maowang1991/archive/2012/12/06/2806121.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值