题目大意:找出假币,如果有多个或者没有输出0.
思路:如果是假币每次都会出现在不等式的同一端就能找到啦。
代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
int a[] = new int[1005];
int b[] = new int[1005];
int c[] = new int[1005];
int count = 0;
for (int i = 0; i < k; i++) {
int p = scan.nextInt();
for (int j = 0; j < p * 2; j++) {
c[j] = scan.nextInt();
}
String d = scan.next();
if (d.equals("=")) {
for (int j = 0; j < p * 2; j++) {
a[c[j]] = 1;
}
}
if (d.equals("<")) {
count++;
for (int j = 0; j < p; j++) {
b[c[j]]--;
}
for (int j = p; j < p * 2; j++) {
b[c[j]]++;
}
}
if (d.equals(">")) {
count++;
for (int j = 0; j < p; j++) {
b[c[j]]++;
}
for (int j = p; j < p * 2; j++) {
b[c[j]]--;
}
}
}
int ans = 0, sum = 0;
for (int j = 1; j <= n; j++) {
if (a[j] == 1)
continue;
else if (b[j] == count || b[j] == -count) {
ans = j;
sum++;
}
}
if (sum == 1)
System.out.println(ans);
else
System.out.println(0);
}
}