Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/480/problem/A
Description
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
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
Sample Input
3
5 2
3 1
4 2
Sample Output
2
HINT
题意
在期末,有一个人准备完成n(n<=5000)门考试,每门考试你可以选择在第ai天考试,也可以在第bi天考试。
但是不管怎么样,最后你所考试的顺序的a[i],一定是非降的
问你,最少第几天能够考完所有试
题解:
贪心就好了,第一维排序,然后第二位排序
然后贪心选最小就行了
代码:
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; pair<int,int> a[]; int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&a[i].first,&a[i].second);
sort(a+,a+n+);
int ans = a[].second;
for(int i=;i<=n;i++)
{
if(a[i].second >= ans)
ans = min(a[i].second,a[i].first);
else
ans = a[i].first;
}
printf("%d\n",ans);
}
Codeforces Round #274 (Div. 1) A. Exams 贪心的更多相关文章
- Codeforces Round #274 (Div. 2) C. Exams (贪心)
题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...
- 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 t ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #274 (Div. 2)
A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...
随机推荐
- <四>面向对象分析之UML核心元素之用例
一:基本概念 --->用例定义了一组用例实例,其中每个实例都是系统所执行一系列操作,这些操作生成特定主角可以观测的值. --->所谓用例,就是一件事情,要完成这 ...
- db file scattered read 等待事件
db file scattered read 等待事件: 我们经常会见到db file scattered read 等待事件,在生产环境中,这个等待事件可能更为常见.这个事件表明用户进程正在读数据 ...
- 【转】cocos2d-x Lua
Call custom c++ from Lua cocos2d-x lua binds c++ class, class functions ,enum and some global functi ...
- JAVA JDK1.5-1.9新特性
1.51.自动装箱与拆箱:2.枚举(常用来设计单例模式)3.静态导入4.可变参数5.内省 1.61.Web服务元数据2.脚本语言支持3.JTable的排序和过滤4.更简单,更强大的JAX-WS5.轻量 ...
- POJ 2421 Constructing Roads
题意:要在n个城市之间建造公路,使城市之间能互相联通,告诉每个城市之间建公路的费用,和已经建好的公路,求最小费用. 解法:最小生成树.先把已经建好的边加进去再跑kruskal或者prim什么的. 代码 ...
- IIS配置网站(WebServices),局域网都能访问
IIS配置网站(WebServices),局域网都能访问 前言 上篇说到在本机创建一个WebServices,用控制台应用程序调用WebServices的SayHello方法. http://www. ...
- (转载) VS编译duilib项目时候的错误解决方法整理
原文地址:http://blog.csdn.net/x356982611/article/details/30217473 @1:找不到Riched20.lib 用everything等软件搜索下磁盘 ...
- 新版本ubuntu13.10软件安装
问题1:如何解决ubunt13.04不能和主机共享文件的问题 . 安装VMware Tools 网上有很多的资料,这里没有给出. . 设置共享文件夹目录 ) 在VMware虚拟机窗口,选择VM-> ...
- 【原】Storm分布式RPC
5. Storm高级篇 序列化 分布式RPC High level overview LinearDRPCTopologyBuilder Local mode DRPC Remote mode DRP ...
- 在Raspberry Pi上安装XBMC
2013-05-22 XBMC is a free and open source media player application developed by the XBMC Foundation, ...