首页  >  文章  >  web前端  >  Codeforces Round #274 (Div. 1) A B C_html/css_WEB-ITnose

Codeforces Round #274 (Div. 1) A B C_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 11:56:031357浏览

昨天一觉起来都5点半了。。没来的及玩,补的题。。

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 <cstdio>#include <cstring>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <cmath>#include <set>#include <map>using namespace std;typedef long long LL;#define min3(a,b,c) min(a,min(b,c))#define max3(a,b,c) max(a,max(b,c))#define pb push_back#define mp(a,b) make_pair(a,b)#define clr(a) memset(a,0,sizeof a)#define clr1(a) memset(a,-1,sizeof a)#define dbg(a) printf("%d\n",a)typedef pair<int> pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)a;int main(){    int n,x,y;    scanf("%d",&n);    for(int i=0;i<n scanf a.pb sort int ans="0;" for i="0;i<n;i++)" if>=ans) ans=a[i].second;        else ans=a[i].first;    }    printf("%d\n",ans);    return 0;}</n></int></map></set></cmath></vector></queue></algorithm></iostream></string.h></cstring></cstdio>

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 <cstdio>#include <cstring>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <cmath>#include <set>#include <map>using namespace std;typedef long long LL;#define min3(a,b,c) min(a,min(b,c))#define max3(a,b,c) max(a,max(b,c))#define pb push_back#define mp(a,b) make_pair(a,b)#define clr(a) memset(a,0,sizeof a)#define clr1(a) memset(a,-1,sizeof a)#define dbg(a) printf("%d\n",a)typedef pair<int> pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)=0&&binary_search(a,a+i,a[i]+x-y))            {                printf("1\n%d\n",a[i]-y);                return 0;            }            if(a[i]+y  <br> C题:  http://codeforces.com/contest/480/problem/C  <p></p>  <p></p>  <p class="sycode">   </p>
<p class="sycode">    C. Riding in a Lift   </p>   <p class="sycode">    </p>
<p class="sycode">     time limit per test    </p> 2 seconds      <p class="sycode">    </p>
<p class="sycode">     memory limit per test    </p> 256 megabytes      <p class="sycode">    </p>
<p class="sycode">     input    </p> standard input      <p class="sycode">    </p>
<p class="sycode">     output    </p> standard output       <p class="sycode">   </p>
<p> Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k consecutive trips in the lift.</p>   <p> Let us suppose that at the moment you are on the floor number x (initially, you were on floor a). For another trip between floors you choose some floor with number y (y?≠?x) and the lift travels to this floor. As you cannot visit floor b with the secret lab, you decided that the distance from the current floor x to the chosen y must be strictly less than the distance from the current floor x to floor b with the secret lab. Formally, it means that the following inequation must fulfill: |x?-?y|?|x?-?b|. After the lift successfully transports you to floor y, you write down number y in your notepad.</p>   <p> Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109?+?7).</p>    <p class="sycode">   </p>
<p class="sycode">    Input   </p>   <p> The first line of the input contains four space-separated integers n, a, b, k (2?≤?n?≤?5000, 1?≤?k?≤?5000, 1?≤?a,?b?≤?n, a?≠?b).</p>    <p class="sycode">   </p>
<p class="sycode">    Output   </p>   <p> Print a single integer ? the remainder after dividing the sought number of sequences by 1000000007 (109?+?7).</p>    <p class="sycode">   </p>
<p class="sycode">    Sample test(s)   </p>   <p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      input     </p>     <pre style="代码" class="precsshei">5 2 4 1

output

input

5 2 4 2

output

input

5 3 4 1

output

Note

Two sequences p1,?p2,?...,?pk and q1,?q2,?...,?qk are distinct, if there is such integer j (1?≤?j?≤?k), that pj?≠?qj.

Notes to the samples:

  1. In the first sample after the first trip you are either on floor 1, or on floor 3, because |1?-?2|?|2?-?4| and |3?-?2|?|2?-?4|.
  2. In the second sample there are two possible sequences: (1,?2); (1,?3). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip.
  3. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip.

题意:一个人在电梯里面初始位置a层,只能上下|a-b|的位置,也不能停在该楼层,问这样走k次后不同的方案有多少种。

分析:dp方程很好写,dp[i][j]表示第走i次时在第j层有多少种方案,但是直接转移O(k*n*n)的复杂度肯定超时。

注意转移时比如第i次到第j层(设j

/** * @author neko01 *///#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <cstring>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <cmath>#include <set>#include <map>using namespace std;typedef long long LL;#define min3(a,b,c) min(a,min(b,c))#define max3(a,b,c) max(a,max(b,c))#define pb push_back#define mp(a,b) make_pair(a,b)#define clr(a) memset(a,0,sizeof a)#define clr1(a) memset(a,-1,sizeof a)#define dbg(a) printf("%d\n",a)typedef pair<int> pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)b) a=n-a+1,b=n-b+1;    for(int i=a;i=mod)            ans-=mod;    }    printf("%I64d\n",ans);    return 0;}</int></map></set></cmath></vector></queue></algorithm></iostream></string.h></cstring></cstdio>




声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn