题目链接:

A. 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 nexams. 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.

Examples
input
3
5 2
3 1
4 2
output
2
input
3
6 1
5 2
4 3
output
6

题意:

每课有两次考试时间,老师会按时间靠后的那个记录,要求老师记录的时间不能下降,问你最少需要多少天才能考完;

思路:

b作为第一关键字,a作为第二关键字,从小到大排序,然后贪心;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=5e3+10;
const double eps=1e-12; pair<int,int>ha[maxn]; int cmp(pair<int,int> x,pair<int,int> y)
{
if(x.first==y.first)return x.second<y.second;
return x.first<y.first;
}
int main()
{
int n;
read(n);
For(i,0,n-1)
{
read(ha[i].first);
read(ha[i].second);
}
sort(ha,ha+n,cmp);
int ans=0;
for(int i=0;i<n;i++)
{
int temp=min(ha[i].first,ha[i].second);
if(temp<ans)temp=max(ha[i].first,ha[i].second);
ans=temp;
}
cout<<ans<<endl;
return 0;
}

  

codeforces 480A A. Exams(贪心)的更多相关文章

  1. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  2. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  3. Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心

    C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  4. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  5. CodeForces 479C Exams 贪心

    题目: C. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

  7. Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)

    题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...

  8. Codeforces Round #274 (Div. 2) C. Exams (贪心)

    题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...

  9. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

随机推荐

  1. FL2440驱动添加(5)ADC驱动学习笔记

    由图可知,模拟ADC分为两部分功能,一部分是触屏功能,另一部分就是普通ADC功能.分别可以产生INT_TC和INT_ADC 两个中断.该ADC模块总共有8个通道可以进行模拟信号的输入,分别是AIN0. ...

  2. [Tool] 透过PowerPoint Online在部落格文章里内嵌简报

    [Tool] 透过PowerPoint Online在部落格文章里内嵌简报 前言 讲课的时候,用PowerPoint做简报,好像已经成了讲课的惯例.而在课后,将课堂简报整理成部落格的文章,如果单纯是在 ...

  3. 文科生也能看懂的iptables教程(转载)

    据说还是个MM, 写得很通俗易懂, 还很诙谐, 原文:http://dallascao.com/cn/iptables-tutorial-for-newbies/ 对于斗胆开始玩vps的文科生来讲,i ...

  4. MVC Html.AntiForgeryToken() 防止CSRF攻击

    转自:http://blog.csdn.net/cpytiger/article/details/8781457 一.MVC中的Html.AntiForgeryToken()是用来防止跨站请求伪造(C ...

  5. Sass学习之路(3)——Sass编译

    Sass的编译也是在我们使用Sass的时候必须要经过的一个步骤,因为".sass"和".scss"文件并不能直接使用<link>标签引用,最终其实还 ...

  6. CSS3选择器(一)

    E[att^='val'] 选择属性值以val开头的任何字符 E[att$='val'] 选择属性值以val结尾的任何字符 E[att*='val'] 选择属性值包含val的任何字符 :root HT ...

  7. ABAP 搜索帮助

    当选择屏幕上的一个字段所参考的数据元素没有建立搜索帮助时,可以手工建立一个: 1.在se11创建一个搜索帮助ZAUTEST,需要输入: (1)描述: (2)选择方法:即搜索帮助显示字段所在的透明表: ...

  8. CRM Look Up 解决方案

    CRM 前瑞开发中关于lookup的开发工作肯定会遇到,例如选中一个客户或者联系人后自动把相关的信息映射到相关记录上,这样可以减少用户的输入工作.我们在CRM 的映射关系中可以配置相关字段的映射可以解 ...

  9. SharePoint 新特性及安装需知

    以下内容转自Kaneboy 大牛,但我在安装正式版的过程中发现一些问题,主要是.net 版本的问题,弄了我一个晚上,我在下面标出来了.我的安装环境是Windows server 2012 R2 关于详 ...

  10. Android子线程更新UI主线程方法之Handler

    背景: 我们开发应用程序的时候,处于线程安全的原因子线程通常是不能直接更新主线程(UI线程)中的UI元素的,那么在Android开发中有几种方法解决这个问题,其中方法之一就是利用Handler处理的. ...