zoukankan      html  css  js  c++  java
  • D

    Description

    学校的大学生艺术中心周日将面向全校各个学院的学生社团开放,但活动中心同时只能供一个社团活动使用,并且每一个社团活动开始后都不能中断。现在各个社团都提交了他们使用该中心的活动计划(即活动的开始时刻和截止时刻)。请设计一个算法来找到一个最佳的分配序列,以能够在大学生艺术中心安排不冲突的尽可能多的社团活动。
    比如有5个活动,开始与截止时刻分别为:



    最佳安排序列为:1,4,5。

    Input

    第一行输入活动数目n(0<n<100);
    以后输入n行,分别输入序号为1到n的活动使用中心的开始时刻a与截止时刻b(a,b为整数且0<=a,b<24,a,b输入以空格分隔)。

    Output

    输出最佳安排序列所包含的各个活动(按照活动被安排的次序,两个活动之间用逗号分隔),如果有多个活动安排序列符合要求输出字典序最小的序列。

    Sample

    Input 

    6
    8 10
    9 16
    11 16
    14 15
    10 14
    7 11

    Output 

    1,5,4
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <string>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 struct act
    10 {
    11     int s, e, id;
    12 }str[105];
    13 
    14 bool cmp(struct act n1, struct act n2)
    15 {
    16     return n1.e<n2.e || (n1.e==n2.e&&n1.id<n2.id);
    17 }
    18 
    19 int main()
    20 {
    21     int n, i, top, now;
    22     int re[105];
    23     cin >> n;
    24     for(i=0;i<n;i++)
    25     {
    26         cin >> str[i].s >> str[i].e;
    27         str[i].id = i+1;
    28     }
    29     sort(str, str+n, cmp);
    30     top = 0;
    31     now = 0;
    32     for(i=0;i<n;i++)
    33     {
    34         if(str[i].s >= now)
    35         {
    36             now = str[i].e;
    37             re[top++] = str[i].id;
    38         }
    39     }
    40     for(i=0;i<top;i++)
    41     {
    42         if(i==top-1) cout << re[i] << endl;
    43         else cout << re[i] << ",";
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    windows p12(pfx)个人证书安装过程
    OpenSSL库验证PKCS7签名
    Crypto库实现PKCS7签名与签名验证
    windows 系统中打开一个数字证书所经历的过程
    DBA不可不知的操作系统内核参数
    MySQL大表优化方案
    深入浅出Cache
    Git Stash用法
    Git服务器搭建全过程分步详解
    laravel 5.1 性能优化对比
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/13768125.html
Copyright © 2011-2022 走看看