Codeforces Round #274 (Div. 1) B. Long Jumps 数学
B. Long Jumps
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/480/problem/B
Description
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
Input
The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.
Output
In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
Sample Input
3 250 185 230
0 185 250
Sample Output
1
230
HINT
题意
给你一个尺子,上面已经有了n个刻度,这把尺子最长l,然后问你最少加几个刻度,就可以测出x和y了
题解:
答案肯定只有0,1,2这三种
答案为0的就很简单,那么就是x存在或者y存在,或者k和k+x同时存在,k和k+y也同时存在
答案为2的也很简单,就把x,y直接输出就好了
答案为1的讨论一下:
1.x或者y其中一个可以由尺子构成
2.尺子上存在k-x-y,那么我们可以构造一个k-x或者k-y就行了
3.尺子上存在k-(y-x),那么我们可以构造k+x,或者k-y就行了
代码:
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
#define maxn 100005
map<int,int> H;
int main()
{
int n,l,x,y;
scanf("%d%d%d%d",&n,&l,&x,&y);
if(x>y)swap(x,y);
int flag1=,flag2=,flag3=;
for(int i=;i<=n;i++)
{
int k;scanf("%d",&k);
H[k]=;
if(H[x])flag1=;
if(H[k-x])flag1=;
if(H[k+x])flag1=;
if(H[k-y])flag2=;
if(H[k+y])flag2=;
if(H[y])flag2=;
if(H[k-x-y])flag3=k-x;
if(H[k-(y-x)])
{
if(k+x<=l)flag3=k+x;
else if(k-y>=)flag3=k-y;
}
}
if(flag1&&flag2)printf("0\n");
else if(flag1)printf("1\n%d\n",y);
else if(flag2)printf("1\n%d\n",x);
else if(flag3)printf("1\n%d\n",flag3);
else printf("2\n%d %d\n",x,y);
}
Codeforces Round #274 (Div. 1) B. Long Jumps 数学的更多相关文章
- Codeforces Round #274 (Div. 2)
A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...
- Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp
C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)
题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...
- Codeforces Round #274 (Div. 2)-C. Exams
http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...
- Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)
Imagine that you are in a building that has exactly n floors. You can move between the floors in a l ...
- Codeforces Round #274 (Div. 2) --A Expression
主题链接:Expression Expression time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- (原创)LAMP教程6-使用SecureCRTPortable工具远程连接centos
(原创)LAMP教程6-使用SecureCRTPortable工具远程连接centos 是的,今天老柯就给大家介绍一款可以远程连接centos的工具,是的这个就是目前,最夯实的,最多人使用的Secur ...
- hdu5073 简单枚举+精度处理
其实这题还是挺简单的,因为移动k个星球后,这k个星球的权值就可以变为0,所以只有剩下的本来就是连着的才是最优解,也就是说要动也是动两端的,那么就O(N)枚举一遍动哪些就好了. 我是在杭电oj题目重现的 ...
- LeetCode题解——Regular Expression Matching
题目: 正则表达式的匹配,'.'能匹配任何一个字符,'*'之前必须有一个字符,两个结合起来表示之前那个字符出现0到无穷次. 解法: 一定要注意'*'必须结合前面的字符一起使用. 代码: class S ...
- C#选择排序详解
选择排序图解 选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的 ...
- 【更新sql server数据项的长度】////【复制数据到另一张表中】
由于设计时没考虑周全,之后发现长度不够,手动修改又不可以... 重新新建也不行啊>>>>>>>>>里面的数据怎么办 so:直接用代码了.... a ...
- eclipse 使用gradle构建系统时候报错
今天启动eclipse后,昨天运行正常的gradle项目报错,无法进行编译,错误信息如下: Unable to start the daemon process. This problem might ...
- UIButton 在 iOS7.0与iOS7.1 中关于enabled的一点区别
前些日子,在一台iOS7.0的设备上进行调试,关于UIButton的一部分代码如下 1 self.btn_loadmore.enabled = NO; 2 [self.btn_loadmore set ...
- 为Elasticsearch添加中文分词
Elasticsearch的中文分词很烂,所以我们需要安装ik.首先从github上下载项目,解压: cd /tmp wget https://github.com/medcl/elasticsear ...
- CodeForces 489C Given Length and Sum of Digits... (贪心)
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...
- CodeForces 176B Word Cut (计数DP)
Word Cut Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...