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个物品,你需要买 ...
随机推荐
- 洛谷 P1085 不高兴的津津
这道题就是经典的条件分支的题https://www.luogu.org/problemnew/show/P1085 code: #include <stdio.h> int main() ...
- linux 如何查看硬盘大小,内存大小等系统信息及硬件信息
一.linux CPU大小[root@idc ~]# cat /proc/cpuinfo |grep "model name" && cat /proc/cpuin ...
- python 2018/8/25
# 含多空格字符串的分割 hello = "hello python hello"print(a.split(" ")) # ['hello', 'python ...
- Linux项目发布流程
Linux项目发布流程(一) 1.安装pyhton3.7 的依赖包 yum -y groupinstall "Development tools" yum -y install z ...
- 大数据学习——yum练习安装jdk
yum list | grep jdk 安装jdk-1.8.0版本 -openjdk* 安装后,执行java -version 配置环境变量 使用vim /etc/profile 编辑profile文 ...
- 如何使用werkzeug创建WSGI APP
注意 : 1.定义__call__的意义 class App(): def __init__(self): pass def method(self): pass app=App() app() #错 ...
- NYOJ-517-最小公倍数,大数啊~~~
最小公倍数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致.但也并非纯粹的偶然:60是个优秀的数字,它的 ...
- [luoguP1360] [USACO07MAR]黄金阵容均衡Gold Balanced L…
传送门 真的骚的一个题,看了半天只会个前缀和+暴力.. 纯考思维.. 良心题解 #include <cstdio> #include <cstring> #include &l ...
- 获取当前日期的T-SQL语句
CONVERT(nvarchar(10),count_time,121): CONVERT为日期转换函数,一般就是在时间类型 (datetime,smalldatetime)与字符串类型(nchar, ...
- BZOJ3126: [Usaco2013 Open]Photo
n<=200000个点,m<=100000个区间,每个区间有且仅有一个点,求最多几个点,无解-1. http://www.cnblogs.com/Chorolop/p/7570191.ht ...