第十三届JAVAB组决赛——7.小球称重
import java.io.*;
import java.util.*;
public class Main{
public static final int N = 1000010;
public static Set<Integer> set = new HashSet<Integer>(); //已经确定的集合
public static Map<Integer, Integer> map = new HashMap<Integer, Integer>(); //被怀疑的集合
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); int m = sc.nextInt();
int k; String op;
while(m-- > 0) {
k = sc.nextInt();
int[] left = new int[k]; int[] right = new int[k];
for(int i = 0; i < k; i++) left[i] = sc.nextInt();
for(int i = 0; i < k; i++) right[i] = sc.nextInt();
op = sc.next();
if(op.equals("<")) {
for(int i = 0; i < k; i++) {
if(!map.containsKey(left[i])) map.put(left[i], 0);
map.put(left[i], map.get(left[i]) + 1);
}
for(int i = 0; i < k; i++) set.add(right[i]);
}else if(op.equals(">")) {
for(int i = 0; i < k; i++) {
if(!map.containsKey(right[i])) map.put(right[i], 0);
map.put(right[i], map.get(right[i]) + 1);
}
for(int i = 0; i < k; i++) set.add(left[i]);
}else {
for(int i = 0; i < k; i++) {
set.add(right[i]);
set.add(left[i]);
}
}
}
Iterator<Integer> it = set.iterator();
while(it.hasNext()) {
int j = (Integer)it.next();
map.remove(j);
}
int max = Integer.MIN_VALUE;
int res = 0;
for(int i : map.keySet())
if(i != 0) if(map.get(i) > max) max = map.get(i);
for(int i : map.keySet())
if(i != 0) if(map.get(i) == max) res++;
if(res != 0)
System.out.println(res);
else
System.out.println(n - set.size());
sc.close();
}
}