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 ...
随机推荐
- 【JSP】JSP动态显示时间
function showtime() { var today; var hour; var second; var minute; var year; var month; var date; va ...
- POJ 1042 Gone Fishing
题意:一个人要在n个湖中钓鱼,湖之间的路径是单向的,只能走1->2->3->...->n这一条线路,告诉你每个湖中一开始能钓到鱼的初始值,和每钓5分钟就减少的数量,以及湖之间的 ...
- TabHost Tab的添加和删除
TabHost 添加Tab项: tabhost = this.getTabHost(); TabSpec tabSpec = tabhost.newTabSpec("news"); ...
- C++ 使用Htmlcxx解析Html内容(VS编译库文件)
1.下载Htmlcxx,http://sourceforge.net/projects/htmlcxx/ 2.解压htmlcxx-0.85.tar.gz 3.打开htmlcxx.vcproj,注意是h ...
- RHCE ext3文件系统故障一例
好久没来了,博客长草了,我来除除草. 给我分了两人,一个统招,一个Java两年开发经验的社招,让我这从工具平台运维往Python开发方向转的工作是举步维艰啊~ 领导看人还是真特么的不准,希望今年招聘的 ...
- ASP.NET导出EXCEL类
最新ASP.NET导出EXCEL类 说明:可以导出ASP.NET页面和DATAGRID(WebControl)数据,可以导出表单头 using System;using System.Data;usi ...
- 将矩阵转化为LibSvm需要的格式
function svmtransform(A)[m,n]=size(A); fid = fopen('A.txt','w');%写入文件路径for i=1:m temp1 = A(i,2:n) ...
- asp.net(class0625)
1 SiteMapPath 面包屑导航控件 要想使用这个控件,必须创建一个站点地图,也就是 web.sitemap web.sitemap是一个xml文件: 根节点必须是:<siteMap> ...
- kobo boot scripts
#!/bin/sh pkill nickel eink_enable_autoupdate rm -rf /debian/tmp/* /debian/tmp/.* 2>/dev/null mou ...
- C# 与 VC Dll 传输信息
考虑: 使用string类型传送: 在VC Dll中解析字符: 使用 string 类型将解析的类型传送到C#程序中: 建立VC解析的函数,提高代码可重用性