【CodeForces 479C】 Exams(排序)
来源:互联网 发布:手机dns软件 编辑:程序博客网 时间:2024/06/07 22:49
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactlyn 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 thei-th subject allowed him to take an exam before the schedule time on daybi (bi < ai). Thus, Valera can take an exam for the i-th subject either on dayai, or on daybi. 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 numberai.
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.
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 integersai andbi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.
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.
35 23 14 2
2
36 15 24 3
6
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组数,每组可选第一个数或第二个数作为记录,第一个数一定大于第二个,顺序可变,但最后的记录数字需是非降序的
思路:按第一个数排序,最终结果一定是第一个数的升序,然后比较第二个,判断第二个是否能用来缩短总时间
#include<iostream>#include<algorithm>#include<cstdio>#define manx 5005using namespace std;struct node{ int a,b;}s[manx];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; scanf("%d",&n); for (int i=0; i<n; i++) scanf("%d%d",&s[i].a,&s[i].b); sort(s,s+n,cmp); int ans=s[0].b; for (int i=1; i<n; i++){ if(s[i].b >= ans) ans=s[i].b; else ans=s[i].a; } printf("%d\n",ans); return 0;}
- 【CodeForces 479C】 Exams(排序)
- codeforces 479B. Towers C - Exams【排序】
- codeforces 479C Exams 排序贪心
- Codeforces-479C-Exams
- codeforces-#479C. Exams(sort)
- Codeforces 479C Exams(贪心)
- Codeforces #274 (Div. 2) C. Exams(贪心:结构体排序)
- C. Exams(Codeforces Round #274)
- Codeforces 497C. Exams 贪心
- CodeForces 492C Vanya and Exams(贪心)
- Codeforces Round #274 (Div. 2) --C Exams
- Codeforces Round #274 (Div. 2) C .Exams
- Codeforces Round #274 (Div. 2) c Exams
- Codeforces Round #274 (Div. 2) C. Exams
- Codeforces 492C Vanya and Exams(贪心)
- CodeForces 492C Vanya and Exams
- Codeforces Round #274(Div2) C. Exams 贪心
- Codeforces-492C-Vanya and Exams
- 快速模算法 A^BmodC
- 并查集
- 技能库--线上jvm内存对象分析(137)
- 百度ueditor富文本编辑器插入html代码问题
- Code Forces 587 A. Duff and Weight Lifting
- 【CodeForces 479C】 Exams(排序)
- Magic Record 使用记录
- poj 3414 Pots(BSF + 记录路径)
- .NET 同步与异步 之 警惕闭包(十)
- TabLayout跟ViewPager进行关联
- Android Webview无法播放美拍网或者优酷网视频,其他视频没问题解决办法。(网页可能暂时无法打开或已永久移至新地址)
- 关联矩阵
- 51nod 1116 K进制下的大数
- 洛谷1341 无序字母对 欧拉路