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 ...
随机推荐
- VS2010开发2dx无法解析的外部符号解决记录
首先新建HelloWorld项目... 想使用Cocos2d扩展包需要引入相关头文件,如:#include “cocos-ext.h”...接下来我们右键工程属性->配置属性->c/c++ ...
- SharePoint 2013让页面显示错误
转:http://blog.csdn.net/zmoneyz/article/details/20460263 1. 在网站端口下,如80端口下的Web.config修改 (1)将<custom ...
- python 去掉\n\t多余空格
>>> import re >>> sss = "SELECT a.id,\n a.customer_id as user_id,\n ...
- C# 类与接口的几个问题的总结(待续)
1. 有关类的多态性 C#中,类的多态性是通过在子类中重载基类的虚方法(virtual标识)或函数成员来实现. 在C#中,继承.虚方法和重写方法组合在一起才能实现多态性. 2. 显式接口成员的使用 显 ...
- C#+AE 用MapControl加载栅格格式文件
需要引入DataSourceRaster命名空间. 具体步骤如下: ①:利用工作控件工厂抽象类定义接口变量,利用工作空间工厂的子类RatserWorkspaceFactory对应的组件类RasterW ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 page_should_not_contain_list(self, locator, message='', loglevel='INFO')
def page_should_not_contain_list(self, locator, message='', loglevel='INFO'): """Veri ...
- DzzOffice添加动态壁纸例子-Bing每日壁纸
Bing每日壁纸介绍:bing网站每天会更新一张不同的精选图片. 此压缩包内的程序,可以自动同步更新cn.bing.com网站每天更新的图片,作为dzzoffice的壁纸使用.实现自动每天更换不同的云 ...
- 【跟我一起学Python吧】Python解释执行原理
这里的解释执行是相对于编译执行而言的.我们都知道,使用C/C++之类的编译性语言编写的程序,是需要从源文件转换成计算机使用的机器语言,经过链接器链接之后形成了二进制的可执行文件.运行该程序的时候,就可 ...
- HDU 3311 Dig The Wells(斯坦纳树)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3311 [题意] 给定k座庙,n个其他点,m条边,点权代表挖井费用,边权代表连边费用,问使得k座庙里 ...
- 将 Sublime 3 打造成 Python/Django IDE
Sublime Text 是一款非常强大的文本编辑器, 下面我们介绍如何将 Sublime Text 3 打造成一款 Python/Django 开发利器: 1. 安装 Sublime Text 3 ...