题目链接:点击打开链接

题意:

输出n l x y

有一根直尺长度为l

上面有n个刻度。

以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l)

要使得 直尺中存在某2个刻度的距离为x 。 某2个刻度的距离为y

要加入最少几个刻度。

问:

最少的刻度个数

输出标记的位置。

思路:

分类讨论一下。。

若本身尺子里就有x、y就输出0

若仅仅有x 或仅仅有y就输出一个刻度。

若2个都没有就:

1、加1个刻度ans。这个ans是距离某个刻度距离为x的,然后看一下是否有距离ans为y的刻度,若有则加入一个ans就可以。

2、第1个都非法时就直接加2个刻度。

<pre name="code" class="cpp">#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')? 0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
ret*=sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x <0) {
putchar('-');
x = -x;
}
if(x>9) pt(x/10);
putchar(x%10+'0');
}
using namespace std;
typedef long long ll;
const int N = 200050; vector<ll>G;
bool Find(ll x){
for(int i = G.size()-2; i > 0; i--)
{
if(G[i] - x < 0)return false;
if( G[lower_bound(G.begin(), G.end(), G[i] - x) - G.begin()] == G[i] - x)
return true;
}
return false;
}
ll n, l, x, y;
ll go(){
ll ans;
for(int i = G.size()-2; i > 0; i--){
ans = G[i]-x;
if(ans >= 0 && ((ans+y<=l&&G[lower_bound(G.begin(), G.end(), ans+y) - G.begin()] == ans+y) || (ans-y>=0&&G[lower_bound(G.begin(), G.end(), ans-y) - G.begin()] == ans-y)))
return ans;
ans = G[i]+x;
if(ans <= l && ((ans + y <= l && G[lower_bound(G.begin(), G.end(), ans+y) - G.begin()] == ans+y) || (ans-y>=0&&G[lower_bound(G.begin(), G.end(), ans-y) - G.begin()] == ans-y)))
return ans;
}
return -1;
}
void input(){
G.clear();
G.push_back(-5000000001LL);
ll tmp;
while(n--){
rd(tmp);
G.push_back(tmp);
}
G.push_back(1e10);
} int main() {
while(cin>>n>>l>>x>>y){
input();
int havx = Find(x), havy = Find(y);
if(havx + havy == 2)
puts("0");
else if(havx + havy == 1)
{
if(havx)
printf("1\n%I64d\n", y);
else
printf("1\n%I64d\n", x);
}
else {
ll ans = go();
if(ans == -1)
{
printf("2\n%I64d %I64d\n", x, y);
}
else
printf("1\n%I64d\n", ans);
}
}
return 0;
}

Codeforces 480B Long Jumps 规律题的更多相关文章

  1. CodeForces 42C Safe cracking 规律题

    题目链接:点击打开链接 3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以 #include<cstdio> #include<cstring> #inc ...

  2. Codeforces - 规律题 [占坑]

    发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...

  3. Codeforces 479D - Long Jumps

    479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...

  4. LightOJ1010---Knights in Chessboard (规律题)

    Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...

  5. ACM_送气球(规律题)

    送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...

  6. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  8. You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]

    补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...

  9. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

随机推荐

  1. Brackets POJ - 2955

    解法 区间dp例题,每次枚举分段点的时候先更新如果开始到结束区间端点有闭合的括号,那么dp[start][end]=dp[start+1][end-1]+2其他照常枚举即可 代码 #include & ...

  2. 牛客OI赛制测试赛2(0906)

    牛客OI赛制测试赛2(0906) A :无序组数 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序意思就是(a,b)和(b,a) 算一组. 输入描述: ...

  3. IO之Object流举例

    import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...

  4. kvm使用kickstart文件自动安装系统

    假定kvm已经准备好 1.创建磁盘 qemu-img create -f qcow2 /kvm/os/vm-01.qcow2 16G 2.上传或下载安装镜像 mkdir -p /kvm/iso cd ...

  5. DB2数据库在线备份还原

    DB2在线备份设置方法: 第一步:开启归档日志 db2 update db cfg for TEST_DB  using logretain on 第二步:重启数据库 第三步:进行一次离线备份 db2 ...

  6. windows本机域名配置

    路径: C:\Windows\System32\drivers\etc打开hosts文件如下: # Copyright (c) - Microsoft Corp. # # This is a samp ...

  7. 我的java web之路(安装)

    所有的软件下载完,陪完jdk之后,迎来了一系列的安装工作... 1.安装SQL Server 2005 首先,打开ISS功能,控制面板->程序->打开或关闭windows功能 注意红框内的 ...

  8. 如何用scanf读入一个string

    #include <stdio.h> #include <string> using namespace std; int main() { string a; a.resiz ...

  9. 算法导论 第一章and第二章(python)

    算法导论 第一章 算法     输入--(算法)-->输出   解决的问题     识别DNA(排序,最长公共子序列,) # 确定一部分用法     互联网快速访问索引     电子商务(数值算 ...

  10. C# 判断字符串为空的4种方法及效率

    在程序开发过程中,少不了要处理字符串,并且常常要判断字符串是否为空,通常有哪些判断方法,以及不同方法的效率又怎么样? 在 C# 中,通常有三种判断字符串是否为空的方法,下面分别探讨. 1.str.Le ...