活动选择问题

叁歲伎倆 2022-07-13 04:52 233阅读 0赞

Problem Description

sdut 大学生艺术中心每天都有n个活动申请举办,但是为了举办更多的活动,必须要放弃一些活动,求出每天最多能举办多少活动。

Input

输入包括多组输入,每组输入第一行为申请的活动数n(n<100),从第2行到n+1行,每行两个数,是每个活动的开始时间b,结束时间e;

Output

输出每天最多能举办的活动数。

Example Input

  1. 12
  2. 15 20
  3. 15 19
  4. 8 18
  5. 10 15
  6. 4 14
  7. 6 12
  8. 5 10
  9. 2 9
  10. 3 8
  11. 0 7
  12. 3 4
  13. 1 3

Example Output

  1. 5
  2. #include<stdio.h>
  3. struct node
  4. {
  5. int again;
  6. int end;
  7. }a[100],abc;
  8. int main()
  9. {
  10. int n;
  11. int i,j;
  12. int count=0;
  13. int ans;
  14. while(scanf("%d",&n)!=EOF)
  15. {
  16. count=0;
  17. for(i=0;i<n;i++)
  18. {
  19. scanf("%d%d",&a[i].again,&a[i].end);
  20. }
  21. for(i=0;i<n-1;i++)
  22. {
  23. for(j=0;j<n-1-i;j++)
  24. {
  25. if(a[j].end>a[j+1].end)
  26. {
  27. abc=a[j];
  28. a[j]=a[j+1];
  29. a[j+1]=abc;
  30. }
  31. }
  32. }
  33. ans=a[0].end;
  34. count++;
  35. for(i=1;i<n;i++)
  36. {
  37. if(a[i].again>=ans)
  38. {
  39. ans=a[i].end;
  40. count++;
  41. }
  42. }
  43. printf("%d\n",count);
  44. }
  45. return 0;
  46. }

发表评论

表情:
评论列表 (有 0 条评论,233人围观)

还没有评论,来说两句吧...

相关阅读

    相关 活动选择问题

    Problem Description sdut 大学生艺术中心每天都有n个活动申请举办,但是为了举办更多的活动,必须要放弃一些活动,求出每天最多能举办多少活动。 Inpu

    相关 活动选择

    活动选择 Problem Description 学校的大学生艺术中心周日将面向全校各个学院的学生社团开放,但活动中心同时只能供一个社团活动使用,并且每一个社团活动开始后

    相关 活动选择

    活动选择 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 学校的大学生艺术中心周日将面