Codeforces 479c (五一训练 I)

<div class="header"><div class="title">C. Exams</div><div class="time-limit"><div class="property-title">time limit per test</div>1 second</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly <span class="tex-span"><em>n</em></span> exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.</p><p>According to the schedule, a student can take the exam for the <span class="tex-span"><em>i</em></span>-th subject on the day number <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub></span>. However, Valera has made an arrangement with each teacher and the teacher of the <span class="tex-span"><em>i</em></span>-th subject allowed him to take an exam before the schedule time on day <span class="tex-span"><em>b</em><sub class="lower-index"><em>i</em></sub></span> (<span class="tex-span"><em>b</em><sub class="lower-index"><em>i</em></sub> < <em>a</em><sub class="lower-index"><em>i</em></sub></span>). Thus, Valera can take an exam for the <span class="tex-span"><em>i</em></span>-th subject either on day <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub></span>, or on day <span class="tex-span"><em>b</em><sub class="lower-index"><em>i</em></sub></span>. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub></span>.</p><p>Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains a single positive integer <span class="tex-span"><em>n</em></span> (<span class="tex-span">1 ≤ <em>n</em> ≤ 5000</span>) — the number of exams Valera will take.</p><p>Each of the next <span class="tex-span"><em>n</em></span> lines contains two positive space-separated integers <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub></span> and <span class="tex-span"><em>b</em><sub class="lower-index"><em>i</em></sub></span> (<span class="tex-span">1 ≤ <em>b</em><sub class="lower-index"><em>i</em></sub> < <em>a</em><sub class="lower-index"><em>i</em></sub> ≤ 10<sup class="upper-index">9</sup></span>) — the date of the exam in the schedule and the early date of passing the <span class="tex-span"><em>i</em></span>-th exam, correspondingly.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.</p></div><div class="sample-tests"><div class="section-title">Sample test(s)</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre>3
5 2
3 1
4 2
Output
2
Input
3
6 1
5 2
4 3
Output
6
Note

In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.

In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.

分析:这个人有几门课要考试,但他跟老师说好了可以在另一天考,求他用最少的天数,可以使考试进度表非降序排列。
 
简单的排序题。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct node
{
    int a;
    int b;
}p[10010];
bool cmp(node x,node y)
{
    if(x.a==y.a)
    return x.b<y.b;
    return x.a<y.a;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i].a>>p[i].b;
    sort(p,p+n,cmp);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(p[i].b>=ans)
        ans=p[i].b;
        else
        ans=p[i].a;
    }
    cout<<ans<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值