yukicoder-602
从 Trac 迁移的文章
这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。
原文章内容如下:
{{{
#!html
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="http://10.71.10.90/sfiction/tool/MathJax/MathJax-master/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
.input, pre {
display: block;
padding: 9.5px;
margin: 0 0 10px;
font-size: 13px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
}}}
== [https://yukicoder.me/problems/no/602 No.602 隠されていたゲーム2] ==
=== Description ===
{{{
#!html
<p>你要从$(0, 0)$移动到$(x, y)$, 每一步移动的曼哈顿距离必须是给出的$N$个数$d_i$中的一个。问至少几步才能到,答案大于2或不存在时输出-1。</p>
}}}
=== Input ===
{{{
#!html
<p class="input">
$N$<br>
$d_1$ $\dots$ $d_n$<br>
$x$ $y$<br>
</p>
<p>$1 \le N \le 10^5, 1 \le d_i \le 10^9, -10^9 \le x, y \le 10^9$</p>
}}}
=== Output ===
{{{
#!html
<p>输出最少需要的步数,如果两步之内无法到达则输出-1</p>
}}}
=== Sample ===
==== Sample 1 ====
输入
{{{
#!html
<pre>
4
3 4 5 13
8 0
</pre>
}}}
输出
{{{
#!html
<pre>
2
</pre>
}}}
==== Sample 2 ====
输入
{{{
#!html
<pre>
1
5
-2 -3
</pre>
}}}
输出
{{{
#!html
<pre>
1
</pre>
}}}
==== Sample 3 ====
输入
{{{
#!html
<pre>
1
14
51 4
</pre>
}}}
输出
{{{
#!html
<pre>
-1
</pre>
}}}
No.602 隠されていたゲーム2
Description
你要从$(0, 0)$移动到$(x, y)$, 每一步移动的曼哈顿距离必须是给出的$N$个数$d_i$中的一个。问至少几步才能到,答案大于2或不存在时输出-1。
Input
$N$
$d_1$ $\dots$ $d_n$
$x$ $y$
$1 \le N \le 10^5, 1 \le d_i \le 10^9, -10^9 \le x, y \le 10^9$
Output
输出最少需要的步数,如果两步之内无法到达则输出-1
Sample
Sample 1
输入
43 4 5 138 0
输出
2
Sample 2
输入
15-2 -3
输出
1
Sample 3
输入
11451 4
输出
-1