POJ 1828

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 //======================================================
 5 struct Point
 6 {
 7     int x;int y;
 8     int flag;
 9 };
10 struct Point p[50050];
11 int n;
12 //======================================================
13 //原来自己用了两方面即想x相同时比y,y相同时比x,两个排序,两个比较,超时。没有下面方法好,只用了一半。。。要好好加油了~TVT.
14 //按照x从小到大排序,当x相等时按照y从大到小排序,从左到右,见到最高的就加一,counter初始值为1
15 //即x最大时,y中也是最大值的p[n-1].y一定是,然后就像爬楼梯一样比较
16 int cmp1( const void *a , const void *b )
17 {
18     struct Point *= (Point *)a;
19     struct Point *= (Point *)b;
20     if(c->!= d->x) return c->- d->x;
21     else return c->- d->y;
22 }
23 
24 
25 //==============================================================
26 int main()
27 {
28 
29     while(scanf("%d",&n)!=EOF&&n)
30     {
31         int counter=1;
32         memset(p,0,sizeof(p));
33         for(int i=0;i<n;++i)
34         {
35             cin>>p[i].x>>p[i].y;
36         }
37         qsort(p,n,sizeof(p[0]),cmp1);//按照x从小到大排序,当x相等时按照y从大到小排序
38         //从左到右,见到最高的就加一
39         int max=p[n-1].y;
40         for(int i=n-2;i>=0;--i)
41         {
42             if(p[i].y>max)
43             {
44                 counter++;
45                 max=p[i].y;
46             }
47         }
48         printf("%d\n",counter);
49     }
50     
51 }

posted on 2011-11-24 11:39 四也 阅读(269) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜