日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 480B B. Long Jumps(贪心)

發(fā)布時(shí)間:2025/3/21 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 480B B. Long Jumps(贪心) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:

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?<?y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances?x?and?y.

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?<?y?≤?l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.

The second line contains a sequence of?n?integers?a1,?a2,?...,?an?(0?=?a1?<?a2?<?...?<?an?=?l), where?ai?shows the distance from the?i-th mark to the origin.

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.

Examples input 3 250 185 230
0 185 250 output 1
230 input 4 250 185 230
0 20 185 250 output 0 input 2 300 185 230
0 300 output 2
185 230

題意:

現(xiàn)在有個(gè)長為l的尺子,上面有n個(gè)標(biāo)記,現(xiàn)在要量兩個(gè)長度x和y,問最小加幾個(gè)標(biāo)記才可以;分別加在哪;

思路:

最多要加兩個(gè)標(biāo)記,如果有標(biāo)記恰好間隔x,y那么就可以直接量了,如果有一個(gè)可以量,那么再加另外一個(gè)就好了,要是兩個(gè)都不能量,但加一個(gè)可以量兩個(gè),那么加一個(gè)就好,否則加兩個(gè),判斷就用map;

AC代碼:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include <map>using namespace std;#define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss));typedef long long LL;template<class T> void read(T&num) {char CH; bool F=false;for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) {if(!p) { puts("0"); return; }while(p) stk[++ tp] = p%10, p/=10;while(tp) putchar(stk[tp--] + '0');putchar('\n'); }const LL mod=1e9+7; const double PI=acos(-1.0); const int inf=1e9; const int N=1e6+20; const int maxn=5e3+10; const double eps=1e-12;int n; LL l,x,y,a[N]; map<LL,int>mp; int check1(LL d) {for(int i=1;i<=n;i++){LL temp=a[i]+d;if(mp[temp])return 1;}return 0; } int check2() {for(int i=1;i<=n;i++){LL temp=a[i]+x+y;if(mp[temp]){cout<<"1\n";cout<<a[i]+x<<endl;return 0;}}LL leng=y-x;for(int i=1;i<=n;i++){LL temp=a[i]+leng;if(mp[temp]){if(temp+x<=l){cout<<"1\n";cout<<temp+x<<endl;return 0;}if(a[i]-x>=0){cout<<"1\n";cout<<a[i]-x<<endl;return 0;}}}cout<<"2"<<endl;cout<<x<<" "<<y<<endl;return 0; } int main() {read(n);read(l);read(x);read(y);For(i,1,n)read(a[i]),mp[a[i]]=1;int fx=check1(x),fy=check1(y);if(fx&&fy)cout<<"0\n";else if(fx||fy){if(fx)cout<<"1\n"<<y<<endl;else cout<<"1\n"<<x<<endl;}else check2();return 0; }

  

轉(zhuǎn)載于:https://www.cnblogs.com/zhangchengc919/p/5843903.html

總結(jié)

以上是生活随笔為你收集整理的codeforces 480B B. Long Jumps(贪心)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。