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个物品,你需要买 ...
随机推荐
- 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x003E2000).错误
这个错误是“栈溢出”,每个线程的栈空间默认是1MB,局部变量(非静态)都在栈中分配,当使用的局部变量所需空间过多时,就会溢出.你检查一下程序,看看哪些函数中定义了大数组,把大数组改成用new分配,函数 ...
- 如何让线程A等待B执行结束后执行?
1. 使用条件变量 判断是否任务B已经做完,然后再执行任务A. 测试代码可看:https://blog.csdn.net/guochao6531/article/details/78075882 2. ...
- Java中的线程安全和非线程安全以及锁的几个知识点
1. 线程安全就是多线程访问时,采用了加锁机制,当一个线程访问该类的某个数据时,进行保护,其他线程不能进行访问直到该线程读取完,其他线程才可使用.不会出现数据不一致或者数据污染. 线程不安全就是不提供 ...
- bzoj3272 Zgg吃东西
题目描述: bz 题解: 线段树模拟费用流. 想法和种树有点类似. 每次取区间内权值和最大的一段,然后整体乘$-1$,代表再次选中时会去掉之前的影响. 线段树维护一堆东西…… 小白逛公园双倍快乐.乘$ ...
- MySQL索引之博客荐读
推荐博客: 寒江独钓. 浅谈算法和数据结构: 十 平衡查找树之B树 张洋. MySQL索引背后的数据结构及算法原理 漫画算法:什么是 B+ 树? B树和B+树的插入.删除图文详解 Jeremy Col ...
- 访问修饰词--Java
public(公共的) 权限: 完全公开 protected(受保护的) 权限: 对子类和同包中的其他类公开 default(默认的,可不写) 权限: 对同包中的其他类公开 private(私有的) ...
- OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档ID 1410.1)
OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档I ...
- ES5的数组方法
参考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array Array.prot ...
- POJ 1287 Networking (最小生成树模板题)
Description You are assigned to design network connections between certain points in a wide area. Yo ...
- 发布tomcate时报A configuration error occurred during startup.please verify the preference field with the prompat:null
发布tomcate时报A configuration error occurred during startup.please verify the preference field with the ...