1. 程式人生 > >2018.8.18 位元組跳動 抖音題

2018.8.18 位元組跳動 抖音題

這裡寫圖片描述

#pragma once
#pragma execution_character_set("utf-8")
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int M, N;
    vector<pair<int,int>> vecInput;
    cin >> N >> M;
    int tmp1,tmp2;
    for (int i = 0; i < N; i++)
    {
        cin
>> tmp1>>tmp2; vecInput.push_back(make_pair(tmp1,tmp2)); } sort(vecInput.begin(), vecInput.end(), [](pair<int, int> &p1, pair<int, int> &p2){return p1.first < p2.first; }); int max=0; for (int i = 0; i < N; i++) { int sum = 1; int
j = i; int key = vecInput[i].second; while (j != N-1) { if (key <= vecInput[j + 1].first) { key = vecInput[j + 1].second; sum++; } j++; } max = max > sum ? max : sum; } cout
<< max << endl; return 0; }

如有漏洞請留言交流