Codeforces Round #274 (Div. 2)-C. Exams
http://codeforces.com/contest/479/problem/C
1 second
256 megabytes
standard input
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.
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.
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.
3
5 2
3 1
4 2
2
3
6 1
5 2
4 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门考试的最晚考试时间可最早考试时间,求最后一门考试的最早时间
按最晚时间升序排列,若相同则最早时间升序,贪心即可
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 struct A{
6 int s;
7 int e;
8 }a[];
9
int cmp(const void *a, const void *b){
struct A *c = (struct A *)a;
struct A *d = (struct A *)b;
if(c->s != d->s)
return c->s - d->s;
else return
c->e - d->e;
}
int main(){
int n, i, ans;
while(scanf("%d", &n) != EOF){
for(i = ; i < n; i++){
scanf("%d %d", &a[i].s, &a[i].e);
}
qsort(a, n, sizeof(a[]), cmp);
ans = -;
for(i = ; i < n; i++){
if(ans <= a[i].e){
ans = a[i].e;
}
else{
ans = a[i].s;
}
}
printf("%d\n", ans);
}
return ;
38 }
Codeforces Round #274 (Div. 2)-C. Exams的更多相关文章
- 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 ...
- Codeforces Round #274 (Div. 2) C. Exams (贪心)
题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #377 (Div. 2) D. Exams(二分答案)
D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...
- Codeforces Round #377 (Div. 2) D. Exams 二分
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #274 (Div. 2)
A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...
- Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp
C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...
- Codeforces Round #274 (Div. 1) B. Long Jumps 数学
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...
随机推荐
- E20180605-hm
arbitrary adj. 乱; 随意的,任性的,随心所欲的; 主观的,武断的; 霸道的,专制的,专横的,独断独行的; session n. 开会,会议; (法庭的) 开庭; 会期,学期; (进行某 ...
- 无法序列化会话状态。请注意,当会话状态模式为“StateServer”或“SQLServer”时,不允许使用无法序列化的对象或 MarshalByRef 对象。
原文链接:http://blog.csdn.net/byondocean/article/details/7564502 session是工作在你的应用程序进程中的.asp.net进程.iis往往会在 ...
- char*和CStringA互转
char*->CStringA char* ch1 = "中文测试123"; CStringA str(ch1); CStringA->char* char* ch2 ...
- lightoj1047 【简单线性DP】
因为写不出hdu3401...好像要用单调队列优化...这边水了一个... 题意: 给n个房子涂色,给出n个房子对应颜色的花费,问涂完所有颜色花费最少. 保证相邻房子颜色不能相同. 思路: dp[i] ...
- timewrap 算法
何为延迟补偿?如何进行坐标差值?B客户端屏幕上A已经跑到东边了,但是收到服务器说"A正在西边往北跑",B到底该何去何从?我若干年前的一个实现版本,将简明扼要的解决这个问题: 影子跟 ...
- Unity3D研究院之手游开发中所有特殊的文件夹
这里列举出手游开发中用到了所有特殊文件夹. 1.Editor Editor文件夹可以在根目录下,也可以在子目录里,只要名子叫Editor就可以.比如目录:/xxx/xxx/Editor 和 /Edi ...
- Bloomberg Desktop Api 关于历史Tick数据的一些参考
使用WAPI命令可以看到当前BBG的Api情况. 目前2016年3月是V3的版本.其中有一个API Develper's Guide 中有Core Develper Guide的pdf, 里面提到了B ...
- Web前端篇:CSS常用格式化排版、盒模型、浮动、定位、背景边框属性
目录 Web前端篇:CSS常用格式化排版.盒模型.浮动.定位.背景边框属性 1.常用格式化排版 2.CSS盒模型 3.浮动 4.定位 5.背景属性和边框属性 6.网页中规范和错误问题 7.显示方式 W ...
- assembly x86(nasm)修改后的日常
data segment ENG db 'SUNdayS Coming I Wanna Drive My Car,SUN,SUN$' ;9,3 sun1 db 'SUN' swcount db 0ah ...
- bzoj1125:[POI2008]Poc
传送门 这个题好难卡啊. 看到这种题自然会想到字符串hash是不是,但是对于每次操作造成的影响需要\(O(n)\)的时间去更新,自然是不优的 可以发现这个更新可以用数据结构来维护,对于每个hash值开 ...