题目链接:点击打开链接

题意:

输出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. 「 Luogu P2420 」 让我们异或吧

    # 解题思路 两点之间的路径的话一定经过它们两个 LCA,这一点已经是显而易见的,那么再来看看异或的性质. $$a\ xor\ b\ xor\ b = a\\ a\ xor\ a=0\\ a\ xor ...

  2. LeetCode(14)Longest Common Prefix

    题目 Write a function to find the longest common prefix string amongst an array of strings. 分析 该题目是求一个 ...

  3. Python+selenium常用方法(Webdriver API)

    小编整理了目前学习的Python+selenium常用的一些方法函数,以后有新增再随时更新. 加载浏览器驱动: webdriver.Firefox() 打开页面:get() 关闭浏览器:quit() ...

  4. python-001 第一个Python3.x程序 hello world

    我们可以使用以下命令来查看我们使用的Python版本: (d:\ProgramData\Anaconda3) C:\Users\Administrator.2016-20160920ET>pyt ...

  5. 【数据传输 2】批量导入的前奏:将Excel表中的数据转换为DataTable类型

    导读:我们知道,在数据库中,数据集DataSet是由多张DataTable表组成.所以,如果我们需要将数据从外部导入到数据库中,那么要做的很重要的一步是将这些数据转换为数据库可以接受的结构.今天在用S ...

  6. FZU2206函数求解

    Problem 2206 函数求解 Accept: 154    Submit: 456 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  7. c# 类如何生成dll文件及引用

    1.打开“工具”菜单下的“外部工具”子菜单: 2.点击“添加按钮,增加一个菜单,菜单内容填写如下: 注意参数那里为:/k "C:\vs2010\VC\vcvarsall.bat" ...

  8. iview自定义配置

    说明 iview是一套基于 Vue.js 的高质量 UI 组件库.主要用户PC端页面设计. 官网:https://www.iviewui.com/ 1.在vue-cli项目中,添加该框架 第一步,安装 ...

  9. FastDfs + Dht 搭建笔记

    以下为搭建一套分布式文件集群系统,参考了很多资料,自己经过在服务器上搭建并且经过了测试.记录以方便以后使用查看. FastDfs + Dht 安装手册 一:概述 FastDFS是由淘宝的余庆先生所开发 ...

  10. ubuntu-12.04下安装postgresql

    2013-10-01 20:42:57|    moniter参考资料:Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)一.安装postgresqlbamboo@bam ...