<h4 style="font-family: 'Open Sans', sans-serif; line-height: 1; margin-top: 0px; text-rendering: optimizelegibility; font-size: 3rem; color: rgb(58, 65, 69);">题意</h4><p style="margin-top: 1.6em; margin-bottom: 1.6em; color: rgb(58, 65, 69); font-family: 'Noto Serif', serif; font-size: 20px; line-height: 32px;">有一个长l的尺上面有n个刻度,求最少需要再添加几个刻度可以测量出长度x和长度y。</p><h4 style="font-family: 'Open Sans', sans-serif; line-height: 1; margin-top: 0px; text-rendering: optimizelegibility; font-size: 3rem; color: rgb(58, 65, 69);">思路分析</h4><p style="margin-top: 1.6em; margin-bottom: 1.6em; color: rgb(58, 65, 69); font-family: 'Noto Serif', serif; font-size: 20px; line-height: 32px;">对于每个已有的刻度判断有没有一个距离它为x和y的刻度就可以了。如果只有1个不能测量,那么就输出那个。如果有两个就比较麻烦了,需要判断一下会不会添加一个就能让两个都有的情况,就可以了。</p>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
const int maxn = 100010;
int n, l, x, y;
set<int> dis;
set<int> test;
int main() {
cin >> n >> l >> x >> y;
dis.clear();
test.clear();
for(int i = 0; i < n; i++){
int tmp;
cin >> tmp;
dis.insert(tmp);
}
int ans = 2;
bool flagx = true;
for(auto iter = dis.begin(); iter != dis.end(); ++iter){
auto iter2 = dis.find(*iter - x);
if(iter2 != dis.end()){
flagx = false;
break;
}
}
if(!flagx) ans--;
bool flagy = true;
for(auto iter = dis.begin(); iter != dis.end(); ++iter){
auto iter2 = dis.find(*iter - y);
if(iter2 != dis.end()){
flagy = false;
break;
}
}
if(!flagy) ans--;
if(ans == 0){
cout << ans << endl;
return 0;
}
if(ans == 1){
cout << "1" << endl;
if(flagx) cout << x << endl;
if(flagy) cout << y << endl;
return 0;
}
if(ans == 2){
for(auto iter = dis.begin(); iter != dis.end(); ++iter){
if(((*iter) + x) <= l)
test.insert(*iter + x);
if(((*iter) - x) >= 0)
test.insert(*iter - x);
}
for(auto iter = test.begin(); iter != test.end(); ++iter){
auto iter2 = dis.find(*iter - y);
if(iter2 != dis.end()){
cout << "1" << endl;
cout << (*iter) << endl;
return 0;
}
auto iter3 = dis.find(*iter + y);
if(iter3 != dis.end()){
cout << "1" << endl;
cout << (*iter) << endl;
return 0;
}
}
cout << "2" << endl;
cout << x << " " << y << endl;
}
return 0;
}