hdu 1051 Wooden Sticks

http://acm.hdu.edu.cn/showproblem.php?pid=1051  先对length排序,再找出weight的递增序列(不一定连续) 个数

View Code
 1 #include<iostream>
2 #include<cstring>
3 #include<algorithm>
4 using namespace std;
5 struct node
6 {
7 int x,y;
8 };
9 node a[5008];
10 bool flag[5008];
11 int n;
12 bool cmp(const node &a,const node &b)
13 {
14 if(a.x==b.x) return a.y<b.y;
15 else return a.x<b.x;
16 }
17 void process()
18 {
19 memset(flag,false,sizeof(flag));//
20 sort(a,a+n,cmp);
21 int i,j,cur,num=0;
22 for(i=0;i<n;i++)
23 {
24 if(!flag[i])
25 {
26 flag[i]=true;
27 num++;
28 cur=a[i].y;
29 for(j=i+1;j<n;j++)
30 {
31 if(!flag[j] && a[j].y >=cur) flag[j]=true,cur=a[j].y;
32 }
33 }
34 }
35 cout<<num<<endl;
36 }
37 int main()
38 {
39 int t,i;
40 cin>>t;
41 while(t--)
42 {
43 cin>>n;
44 for(i=0;i<n;i++) cin>>a[i].x>>a[i].y;
45 process();
46 }
47 //system("pause");
48 return 0;
49 }


 

posted @ 2012-04-02 11:07  keepmoving89  阅读(229)  评论(0编辑  收藏  举报