zoukankan      html  css  js  c++  java
  • Codeforces Round #274 (Div. 2)-C. Exams

    http://codeforces.com/contest/479/problem/C

    C. Exams
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n 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.

    According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. 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 ai.

    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.

    Input

    The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take.

    Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

    Output

    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.

    Sample test(s)
    input
    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.

    解题思路:告诉你n门考试的最晚考试时间可最早考试时间,求最后一门考试的最早时间

    按最晚时间升序排列,若相同则最早时间升序,贪心即可

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 
     5 struct A{
     6     int s;
     7     int e;
     8 }a[5050];
     9 
    10 int cmp(const void *a, const void *b){
    11     struct A *c = (struct A *)a;
    12     struct A *d = (struct A *)b;
    13     if(c->s != d->s)
    14         return c->s - d->s;
    15     else return
    16         c->e - d->e;
    17 }
    18 
    19 int main(){
    20     int n, i, ans;
    21     while(scanf("%d", &n) != EOF){
    22         for(i = 0; i < n; i++){
    23             scanf("%d %d", &a[i].s, &a[i].e);
    24         }
    25         qsort(a, n, sizeof(a[0]), cmp);
    26         ans = -1;
    27         for(i = 0; i < n; i++){
    28             if(ans <= a[i].e){
    29                 ans = a[i].e;
    30             }
    31             else{
    32                 ans = a[i].s;
    33             }
    34         }
    35         printf("%d ", ans);
    36     }
    37     return 0;

    38 } 

  • 相关阅读:
    ant实践总结
    Ubuntu安装JDK和Eclipse
    Xp下安装Ubuntu
    [Hadoop] 传智播客新版Hadoop视频教程 段海涛老师Hadoop八天完全攻克Hadoop视频教程 Hadoop开发
    Ctypes简单应用以及PyQt5等简单使用过程中遇到的部分问题
    python初探:关于闭包
    利用Nginx+Frp搭建HTTP正向代理
    C#发送邮件时提示:“不允许使用邮箱名称。服务器响应为:”的错误解决办法
    提倡IT从业人员终身学习
    打算在博客园安家了
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/4044709.html
Copyright © 2011-2022 走看看