zoukankan      html  css  js  c++  java
  • 会场安排问题(贪心)

    解题思路:用结构体对结尾排序,从第一个的结束点比后面的开始点,若小,活动数就加一,依次类推。
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 struct hui
     7 {
     8     int s;
     9     int e;
    10 } a[10000];
    11 bool cmp(hui a,hui b)
    12 {
    13     return a.e < b.e;
    14 }
    15 int main()
    16 {
    17     int n,i,m;
    18     scanf("%d",&m);
    19     while(m--)
    20     {
    21         scanf("%d",&n);
    22         int count=1;
    23         for(i=0; i<n; i++)
    24             scanf("%d%d",&a[i].s,&a[i].e);
    25         sort(a,a+n,cmp);
    26         for(i=0; i<n-1; i++)
    27             if(a[0].e<a[i+1].s)
    28             {
    29                 count++;
    30                 a[0].e=a[i+1].e;
    31             }
    32         printf("%d
    ",count);
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    优化-IO
    优化-cpu
    优化-内存
    系统优化
    snort -- 入侵检测系统
    tripwire--入侵检测系统
    sudo
    selinux
    pptpd
    C++ 内联函数
  • 原文地址:https://www.cnblogs.com/zou-zou/p/5320610.html
Copyright © 2011-2022 走看看