Codeforces Round #274 (Div. 1) A B C_html/css_WEB-ITnose
A题:http://codeforces.com/contest/480/problem/A
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 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?
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?
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
35 23 14 2
output
input
36 15 24 3
output
Note
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.
简单贪心。。按a第一关键字,b第二关键字降序排序下就好。肯定先选满足的b。。
/** * @author neko01 *///#pragma comment(linker, "/STACK:102400000,102400000")#include#include #include #include #include #include #include #include #include #include
B: http://codeforces.com/contest/480/problem/B
B. Long Jumps
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has nmarks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1,?a2,?...,?an, where ai denotes the distance of the i-th mark from the origin (a1?=?0, an?=?l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1?≤?i?≤?j?≤?n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj?-?ai?=?d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x?
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The first line contains four positive space-separated integers n, l, x, y (2?≤?n?≤?105, 2?≤?l?≤?109, 1?≤?x?
The second line contains a sequence of n integers a1,?a2,?...,?an (0?=?a1?
Output
In the first line print a single non-negative integer v ? the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p1,?p2,?...,?pv (0?≤?pi?≤?l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Sample test(s)
input
3 250 185 2300 185 250
output
1230
input
4 250 185 2300 20 185 250
output
input
2 300 185 2300 300
output
2185 230
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
有意思的题。
题意:有一个长为L的尺子,n个刻度,为了测出x和y的长度,问最少要添加几个刻度。
可以用一个set或者二分查找每一个刻度+x,+y是否存在。如果都不存在,那么判断两个刻度之间有没有x+y,y-x的长度,如果有那么只需添加一个就行。代码有点丑233.。
/** * @author neko01 *///#pragma comment(linker, "/STACK:102400000,102400000")#include#include #include #include #include #include #include #include #include #include
推荐阅读
-
Codeforces Round #278 (Div. 2)B?? Candy Boxes_html/css_WEB-ITnose
-
Codeforces Round #272 (Div. 1)D(字符串DP)_html/css_WEB-ITnose
-
Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)_html/css_WEB-ITnose
-
Codeforces Round #258 (Div. 2) B. Jzzhu and Sequences(矩阵快速幂)_html/css_WEB-ITnose
-
Codeforces Round #282 (Div. 2) b_html/css_WEB-ITnose
-
Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences_html/css_WEB-ITnose
-
Codeforces Round #277.5 (Div. 2)B??BerSU Ball_html/css_WEB-ITnose
-
Codeforces Round #274 (Div. 2) D. Long Jumps_html/css_WEB-ITnose
-
Codeforces Round #280 (Div. 2)-B. Vanya and *s_html/css_WEB-ITnose
-
Codeforces Round #277.5 (Div. 2)B??BerSU Ball_html/css_WEB-ITnose