Codeforces 480B Long Jumps 规律题
题目链接:点击打开链接
题意:
输出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 规律题的更多相关文章
- CodeForces 42C Safe cracking 规律题
题目链接:点击打开链接 3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以 #include<cstdio> #include<cstring> #inc ...
- Codeforces - 规律题 [占坑]
发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...
- Codeforces 479D - Long Jumps
479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...
- 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 ...
- ACM_送气球(规律题)
送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...
- hdoj--1005--Number Sequence(规律题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
随机推荐
- BZOJ 1968_P1403 [AHOI2005]约数研究--p2260bzoj2956-模积和∑----信息学中的数论分块
第一部分 P1403 [AHOI2005]约数研究 题目描述 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机“Samuel II”的长时间运算成为了可能.由于在去年一 ...
- python基础(一)—— 核心数据类型
Hello World程序 [root@mysql ~]# python3 Python 3.6.5 (default, Jul 8 2018, 11:41:23) [GCC 4.4.7 20120 ...
- 嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=15873837810484552531 中的1-14讲
#coding=gbk#嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=1587383 ...
- ssm+activiti+maven
1spring整合activiti中添加activiti依赖 <!-- 添加Activiti支持 --> <dependency> <groupId>org.act ...
- Ducci Sequence解题报告
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , ...
- Android开发——GPS定位
1.LocationManager LocationManager系统服务是位置服务的核心组件,它提供了一系列方法来处理与位置相关的问题. 与LocationManager相关的两个知识点: 1.1 ...
- LoadRunner之并发用户数与迭代关系---并发数与迭代的区别
Q1: 例如在LR里,我要测100个用户同时并发登陆所用时间,那我是不是在录制好脚本后,需要参数化“用户名”,“密码”以及在那个记事本里构造100个真实的用户名和密码? 然后运行Controller, ...
- hdu 1879
#include<stdio.h> #include<stdlib.h> #define N 100 struct node { int x,y,dis; }road[N*N] ...
- 【Ural1297】Palindrome(后缀数组)
题意:求一个字符串的最长回文子串 n<=1000 思路:这是一道论文题 需要注意的细节: 1.奇偶分类 2.中间的分割符与最后的附加字母都是最小值,但两者不能相同,否则height可能会出现问题 ...
- 微服务 Framework
Dubbo :https://github.com/dubbo Spring Cloud :https://github.com/spring-cloud