最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#274(Div.1)ABC_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:56:36
文档

CodeforcesRound#274(Div.1)ABC_html/css

CodeforcesRound#274(Div.1)ABC_html/css_WEB-ITnose:昨天一觉起来都5点半了。没来的及玩,补的题。 A题:http://codeforces.com/contest/480/problem/A A. Exams time limit per test 1 second memory limit per test 256 megabytes input
推荐度:
导读CodeforcesRound#274(Div.1)ABC_html/css_WEB-ITnose:昨天一觉起来都5点半了。没来的及玩,补的题。 A题:http://codeforces.com/contest/480/problem/A A. Exams time limit per test 1 second memory limit per test 256 megabytes input

昨天一觉起来都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 #include #include #include #include #include #include #include #include #include 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 pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)<<61)+5;const int mod=1000000007;vectora;int main(){ int n,x,y; scanf("%d",&n); for(int i=0;i=ans) ans=a[i].second; else ans=a[i].first; } printf("%d\n",ans); return 0;}

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 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 pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)<<61)+5;const int N=100005;LL a[N];int main(){ int n; LL l,x,y; scanf("%d%lld%lld%lld",&n,&l,&x,&y); for(int i=0;i=0&&binary_search(a,a+i,a[i]+x-y)) { printf("1\n%d\n",a[i]-y); return 0; } if(a[i]+y<=l&&binary_search(a+i,a+n,a[i]+y-x)) { printf("1\n%d\n",a[i]+y); return 0; } } printf("2\n%I64d %I64d\n",x,y); } else printf("0\n"); return 0;}

C题: http://codeforces.com/contest/480/problem/C

C. Riding in a Lift

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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|?

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).

Input

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).

Output

Print a single integer ? the remainder after dividing the sought number of sequences by 1000000007 (109?+?7).

Sample test(s)

input

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. 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 #include #include #include #include #include #include #include #include #include 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 pp;const double eps=1e-9;const double pi=acos(-1.0);const int INF=0x3f3f3f3f;const LL inf=(((LL)1)<<61)+5;const int mod=1000000007;const int N=5005;LL dp[N];LL sum[N];int main(){ int n,a,b,k; scanf("%d%d%d%d",&n,&a,&b,&k); if(a>b) a=n-a+1,b=n-b+1; for(int i=a;i<=n;i++) sum[i]=1; for(int i=1;i<=k;i++) { for(int j=1;j=mod) ans-=mod; } printf("%I64d\n",ans); return 0;}

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

CodeforcesRound#274(Div.1)ABC_html/css

CodeforcesRound#274(Div.1)ABC_html/css_WEB-ITnose:昨天一觉起来都5点半了。没来的及玩,补的题。 A题:http://codeforces.com/contest/480/problem/A A. Exams time limit per test 1 second memory limit per test 256 megabytes input
推荐度:
标签: div round (1
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top