zoukankan      html  css  js  c++  java
  • 2016HUAS暑假集训训练2 J

    题目链接:https://vjudge.net/contest/121192#problem/J

    此题要求是计算能够看到最多的节目 ,贪心算法即可,首先对结束时间排序,然后在把开始的时间和前面的结束时间比较 如果开始时间大于前面的结束的时间就可以记一次,然后在慢慢累计

    ac代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     int t, i, s, start, a[101][2], tt,j;
     8     while (cin >> t && t != 0)
     9     {
    10         for (i = 0; i < t; i ++)
    11             cin >> a[i][0] >> a[i][1];
    12         for (i = 0; i < t - 1; i ++)            //对结束时间排序  如果相等就对开始时间从小到大排序
    13             for (j = i + 1; j < t; j ++)
    14             {
    15                 if (a[i][1] > a[j][1])
    16                 {
    17                     tt = a[i][1]; a[i][1] = a[j][1]; a[j][1] = tt;
    18                     tt = a[i][0]; a[i][0] = a[j][0]; a[j][0] = tt;
    19                 }
    20                 if (a[i][1] == a[j][1])
    21                 {
    22                     if (a[i][0] > a[j][0])
    23                     {
    24                         tt = a[i][1]; a[i][1] = a[j][1]; a[j][1] = tt;
    25                         tt = a[i][0]; a[i][0] = a[j][0]; a[j][0] = tt;
    26                     }
    27                 }
    28             }
    29                 s  = 1; start = 0;
    30                 for (i = 1; i < t;  i ++)
    31                 {
    32                     if (a[i][0] >= a[start][1])        //计算最多节目
    33                     {
    34                         //cout<<a[i][0]<<"      "<<a[i][1]<<endl;
    35                         start = i;
    36                         s++;
    37                     }
    38                 }
    39                cout<<s<<endl;
    40             }
    41         return 0;
    42     }
  • 相关阅读:
    windows10安装pycharm,以及pycharm教程和破解码
    windows 10安装python3和python2
    Git之仓库管理
    Python操作 Excel表格
    ansible 基础操作
    Flask-Migrate
    flask-script
    flask-sqlalchemy
    基于数字证书的二次登录认证流程
    摘录:识别系统原理(转)
  • 原文地址:https://www.cnblogs.com/LIUWEI123/p/5698724.html
Copyright © 2011-2022 走看看