打卡信奥刷题(1175)用C++实现信奥 P2255 [USACO14JAN] Recording the Moolympics S

P2255 [USACO14JAN] Recording the Moolympics S

题目描述

Being a fan of all cold-weather sports (especially those involving cows),Farmer John wants to record as much of the upcoming winter Moolympics as possible.

The television schedule for the Moolympics consists of N different programs(1 <= N <= 150), each with a designated starting time and ending time. FJ has a dual-tuner recorder that can record two programs simultaneously.

Please help him determine the maximum number of programs he can record in total.

农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目。 moolympics 的节目时间表有 NNN 个不同的节目 (1≤N≤1501\le N\le 1501N150),每个节目给定开始时间和结束时间。FJ 有一个双调谐器录音机,可以同时录制两个节目。 请帮助他确定他能录制的节目的最大数量。

输入格式

* Line 1: The integer N.

* Lines 2…1+N: Each line contains the start and end time of a single program (integers in the range 0…1,000,000,000).

  • 111 行:整数 NNN
  • 222 到第 N+1N+1N+1 行:每行包含单个节目的开始和结束时间(范围为 0…10000000000…100000000001000000000 的整数)。

输出格式

* Line 1: The maximum number of programs FJ can record.

仅一行,FJ可以记录的最大节目数量。

输入输出样例 #1

输入 #1

6
0 3
6 7
3 10
1 5
2 8
1 9

输出 #1

4

说明/提示

INPUT DETAILS:

The Moolympics broadcast consists of 6 programs. The first runs from time 0 to time 3, and so on.

OUTPUT DETAILS:

FJ can record at most 4 programs. For example, he can record programs 1 and 3 back-to-back on the first tuner, and programs 2 and 4 on the second tuner.

Source: USACO 2014 January Contest, Silver

C++实现

#include<bits/stdc++.h>
using namespace std;
int n;
pair<int,int> a[166];
int v[166]={0};
int main(){
    int n;
    cin>>n;
    for (int i=0;i<n;i++) cin>>a[i].second>>a[i].first;
    sort(a,a+n);
    int t1=0,t2=0; 
    int ans=0;
    for (int i=0;i<n;i++){
        if (a[i].second<t1) continue;
        ans++;
        if (a[i].second<t2){
                t1=t2;
                t2=a[i].first;
        } else 
            t2=a[i].first;
    }
    cout<<ans<<'\n';
    return 0;
}

在这里插入图片描述

后续

接下来我会不断用C++来实现信奥比赛中的算法题、GESP考级编程题实现、白名单赛事考题实现,记录日常的编程生活、比赛心得,感兴趣的请关注,我后续将继续分享相关内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值