Skip to content

Instantly share code, notes, and snippets.

@hiroshi-cl
Created November 11, 2013 09:15
Show Gist options
  • Save hiroshi-cl/7410264 to your computer and use it in GitHub Desktop.
Save hiroshi-cl/7410264 to your computer and use it in GitHub Desktop.
2013年 模擬地区予選 Problem A: Broken Audio Signal (解法1) [Licence: NYSL Version 0.9982]
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(final String... args) {
final Scanner sc = new Scanner(System.in);
main:
while (sc.hasNext()) {
final int n = sc.nextInt();
if (n == 0)
return;
final String[] in = new String[n];
for (int i = 0; i < n; i++)
in[i] = sc.next().intern();
final Set<Integer> set = new HashSet<>();
for (final String s : in)
if (s != "x") {
final int i = Integer.parseInt(s);
set.add(i + 1);
set.add(i - 1);
}
set.add(Integer.MAX_VALUE);
set.add(Integer.MIN_VALUE);
boolean f = false;
int ans = 0;
loop:
for (final int i : set) {
final int[] is = new int[n];
for (int j = 0; j < n; j++)
if (in[j] == "x")
is[j] = i;
else
is[j] = Integer.parseInt(in[j]);
for (int j = 1; j < n; j++)
if (j % 2 == 0) {
if (is[j - 1] <= is[j])
continue loop;
} else if (is[j - 1] >= is[j])
continue loop;
if (f) {
System.out.println("ambiguous");
continue main;
}
f = true;
ans = i;
}
if (f)
System.out.println(ans);
else
System.out.println("none");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment