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

    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
    题意:一个人要參加n场考试,考试规定时间是ai,可是能够提前到bi,他要依照时间的顺序參加,在同一个时间能够做若干件事情。求最早的考完时间

    思路:先依照规定时间排序。然后是每次记录上次考试的时间

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    typedef long long ll;
    using namespace std;
    const int maxn = 5005;
    
    struct Node {
    	ll x, y;
    } node[maxn];
    
    int cmp(Node a, Node b) {
    	if (a.x != b.x)
    		return a.x < b.x;
    	return a.y < b.y;
    }
    
    int main() {
    	int n;
    	scanf("%d", &n);
    	for (int i = 0; i < n; i++) 
    		scanf("%lld%lld", &node[i].x, &node[i].y);
    	
    	sort(node, node+n, cmp);
    	ll ans = 1;
    	for (int i = 0; i < n; i++) {
    		if (node[i].y >= ans)
    			ans = node[i].y;
    		else ans = node[i].x;
    	}
    	printf("%lld
    ", ans);	
    	return 0;
    }



  • 相关阅读:
    2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683
    hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
    最小费用最大流粗解 poj2516
    hdu3078 建层次树+在线LCA算法+排序
    hdu 3594 Cactus /uva 10510 仙人掌图判定
    有向图最小路径覆盖方法浅析、证明 //hdu 3861
    hdu 1827 有向图缩点看度数
    条件转化,2-sat BZOJ 1997
    2-sat基础题 BZOJ 1823
    2-sat 分类讨论 UVALIVE 3713
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6953539.html
Copyright © 2011-2022 走看看