codeforces 479C Exams 解题报告

题目链接:http://codeforces.com/problemset/problem/479/C

题目意思:简单来说,就是有个人需要通过 n 门考试,每场考试他可以选择ai, bi 这其中一个时间来考,要求 n 门考试过后,他所选择的时间序列是一条非递减序列,输出最少时间。

      其实那个最少时间是骗人的,感觉没什么用。直接排序,然后每门课程选择尽可能少的时间来考,但这个时间需要满足 >= 前一门课程的时间。

      感觉这道题比 B 题还要简单,额。。。是错觉了么,不过它题目意思确实有点绕~~~~纸老虎题,把握关键的一些信息即可做出。

     

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define  f  first
#define  s  second
const int maxn = 5000 + 5;
pair<int, int> p[maxn];

int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &p[i].f);
            scanf("%d", &p[i].s);
        }
        sort(p, p+n);
        int pre = min(p[0].f, p[0].s);    // 前一场考试的时间
        
        for (int i = 1; i < n; i++)
        {
            int tmp = min(p[i].f, p[i].s);
            pre = (tmp < pre ? max(p[i].f, p[i].s) : tmp);
        }
        printf("%d
", pre);
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/windysai/p/4040339.html