poj1065

其实是水题一道啊

其实还是要好好想想到底按照什么排序的

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 struct stick
 6 {
 7     int l;
 8     int w;
 9     int flag;
10 };
11 stick a[5005];
12 
13 
14 int cmp( stick a, stick b)
15 {
16     if(a.l!=b.l) return a.l<b.l;
17     else return a.w<b.w;
18 }
19 
20 int main()
21 {
22     int Case;
23     cin>>Case;
24     int n;
25     int tmp;
26     int time;
27     int i,j;
28     while(Case--)
29     {
30         time=0;
31         cin>>n;
32         for(i=0;i<n;i++)
33         {
34             cin>>a[i].l>>a[i].w;
35             a[i].flag=0;
36         }
37         sort(a,a+n,cmp);
38         /*for(i=0;i<n;i++)
39         {
40             cout<<a[i].l<<" "<<a[i].w<<endl;
41         }*/
42         for(i=0;i<n;i++)
43         {
44             if(a[i].flag==0)
45             {
46                 tmp=a[i].w;
47                 a[i].flag=1;
48                 time++;
49                 for(j=i+1;j<n;j++)
50                 {
51                     if(a[j].w>=tmp && a[j].flag==0)
52                     {
53                         a[j].flag=1;
54                         tmp=a[j].w;
55                     }
56                 }
57             }
58         }
59         cout<<time<<endl;
60 
61     }
62     return 0;
63 }

posted on 2012-08-03 18:42  矮人狙击手!  阅读(146)  评论(0编辑  收藏  举报

导航