AcWing 1204. 错误票据
原题链接
简单
作者:
不知名的fE
,
2024-11-23 11:51:37
,
所有人可见
,
阅读 1
暴力枚举nlong(n)
import java.util.*;
public class Main {
static int[] a = new int[10010];
static int idx = 1;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 1; i <= n; i++) toArr(sc.nextLine().split(" "));
Arrays.sort(a, 1, idx);
int x = -1, y = -1;
for (int i = 2; i < idx; i++) {
if (x == -1 && a[i] != a[i - 1] + 1 && a[i] != a[i - 1]) x = a[i - 1] + 1;
if (y == -1 && a[i] == a[i - 1]) y = a[i];
}
System.out.println(x + " " + y);
}
static void toArr(String[] str) {
for (int i = 0; i < str.length; i++) a[idx ++] = Integer.parseInt(str[i]);
}
}
开数组时间复杂度:m(数据范围)对于本题m = 10^5
import java.util.*;
public class Main {
static final int N = 10010;
static int[] a = new int[N];
static boolean[] st = new boolean[N * 10];
static int idx = 1, min = 100100;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 1; i <= n; i++) toArr(sc.nextLine().split(" "));
int x = -1, y = -1;
for (int i = 1; i < idx; i++) {
if (st[a[i]]) y = a[i];
st[a[i]] = true;
}
for (int i = min; x == -1; i++) {
if (!st[i]) x = i;
}
System.out.println(x + " " + y);
}
static void toArr(String[] str) {
for (int i = 0; i < str.length; i++) {
a[idx] = Integer.parseInt(str[i]);
min = Math.min(min, a[idx++]);
}
}
}