Skip to content

Instantly share code, notes, and snippets.

@phonism
Last active December 24, 2015 13:09
Show Gist options
  • Save phonism/6802962 to your computer and use it in GitHub Desktop.
Save phonism/6802962 to your computer and use it in GitHub Desktop.
POJ 2443 Set Operation http://poj.org/problem?id=2443 压位加速
package NO20130926;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class POJ2443 {
public void run() {
InputReader cin = new InputReader(System.in);
PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));
int[][] map = new int[10010][100];
int n = cin.nextInt();
for (int i = 0; i < n; i++) {
int c = cin.nextInt();
for (int j = 0; j < c; j++) {
int x = cin.nextInt();
map[x][i / 30] |= 1 << (i % 30);
}
}
int q = cin.nextInt();
for (int cas = 0; cas < q; cas++) {
int a = cin.nextInt();
int b = cin.nextInt();
boolean ok = false;
for (int i = 0; i < 35; i++) {
if ((map[a][i] & map[b][i]) > 0) {
cout.println("Yes");
ok = true;
break;
}
}
if (ok == false)
cout.println("No");
}
cout.flush();
}
public static void main(String args[]) {
new POJ2443().run();
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public InputReader() throws FileNotFoundException {
reader = new BufferedReader(new FileReader("d:/input.txt"));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment