首页 > 其他 > 详细

贪心/hdu 2037 今年暑假不AC

时间:2014-12-11 23:55:04      阅读:449      评论:0      收藏:0      [点我收藏+]
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 using namespace std;
 5 struct node
 6 {
 7     int st;
 8     int ed;
 9 };
10 node a[110];
11 int n,ans;
12 bool cmp(node x,node y)
13 {
14     if (x.ed==y.ed) return x.st<y.st;
15     return x.ed<y.ed;
16 }
17 int main()
18 {
19     scanf("%d",&n);
20     while (n!=0)
21     {
22         memset(a,0,sizeof(a));
23         for (int i=1;i<=n;i++) scanf("%d%d",&a[i].st,&a[i].ed);
24         sort(a+1,a+n+1,cmp);
25         //for (int i=1;i<=n;i++) printf("%d %d\n",i,a[i].ed);
26         ans=0;
27         int last=0;
28         for (int i=1;i<=n;i++)
29             if (a[i].st>=last)
30             {
31                 ans++;
32                 last=a[i].ed;
33             }
34         printf("%d\n",ans);
35         scanf("%d",&n);
36     }
37     return 0;
38 }

 

贪心/hdu 2037 今年暑假不AC

原文:http://www.cnblogs.com/NicoleLam/p/4158673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!