Codeforces Round #724 (Div. 2)
A. Omkar and Bad Story
题意
当一个数组中任意两个数的绝对值在数组中都存在且每个数都唯一则称这个数组好。现在可以通过向数组中添加任意多个数(数组最终大小不超300),然后判断能否得到一个好数组。
分析
首先数组中数的大小为 [−200, 200],所以考虑负数的情况。假设 b < 0 则 |a - b| > a,所以数组会无限增长从而无法得到一个好数组。而正数差的绝对值的范围定在 [0, 100] 范围内,而数组最多可以有 300 位,所以可以从 0 输出到 299。
代码
public static void solve() throws IOException {
boolean ok = true;
int n = nextInt();
for (int i = 0; i < n; i++) if (nextInt() < 0) ok = false;
if (!ok) {
pw.println("NO");
return ;
}
pw.println("YES");
pw.p