G

来源:互联网 发布:小组积分软件 编辑:程序博客网 时间:2024/04/29 03:50

Description

A university in Samara has held a qualification contest in figure programming, but the jury can't come to terms how many teams should take part in the next stage of the contest. In figure programming a judge system doesn't evaluate the scores precisely and just set an interval which the score can belong to. Jury is able to evaluate any participant with any score from this interval. There are n teams that took part in the contest, and the i-th of them has the score in the interval from li to ri, inclusively. Jury wants the number of qualified teams to be as large as possible, but they have to get the maximal score among all teams. What is the maximal number of teams that can take part in the next stage of the contest under such circumstances?

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of teams in the contest.

Each of the next n lines contains two space-separated integers: li and ri ( - 109 ≤ li ≤ ri ≤  + 109) — the lower and upper bounds of the score for the i-th team.

Output

Output a single integer — the maximal number of teams that can get the maximal score.

Sample Input

Input
31 32 44 5
Output
2

题意:

就是给你几组的测试数据中,每测试数据为一段值,寻找一个最大值。即最大值范围里的最小值要小于其他范围里的最大值,则符合条件!

思路:

运用两个数组来存储每组数据,找到最大分段里的最小值,然后和其它范围里的最大值比较!

细节:

注意先输入的数规定为小后面的为大,如果相反要交换顺序,还有就是范围里面有相同的最大值,此时,谁的最小值大,那么谁的范围取最大值,最大值范围里的最小值与其他范围最大值比较!(我快被绕晕了。。。。。。)还有就是用inf(ox3f3f3f3f)存放最大左值(卡在了这,若没定义#define inf (ox3f3f3f3f3)老是出现run time error on test 2)。

描述不清楚看代码吧:

#include <iostream>using namespace std;#define inf (0x3f3f3f3f)const int maxn = 1e6 + 20;int L[maxn];int R[maxn];int main() {    int n;    cin >> n;    int l = 0;    for (int i = 1; i <= n; ++i) {        cin >> L[i] >> R[i];        if (L[i] > R[i]) swap(L[i], R[i]);    }    int mx = -inf;    int id = inf;    for (int i = 1; i <= n; ++i) {        if (mx < L[i]) {            mx = L[i];            id = i;        } else if (mx == L[i]) {            if (R[id] < R[i]) {                id = i;            }        }    }    int s = 0;    for (int i = 1; i <= n; ++i) {        if (R[i] < L[id]) continue;        s++;    }    cout << s << endl;    return 0;}
心得:

离成功就差一小步,所以需要克服那一小步,加油!!!

0 0
原创粉丝点击