//Google Code Jam Round 1C 2010 A Rope Intranet
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Google Code Jam
public class GoogleCode1 {
private static MyScanner in;
private static PrintStream out;
private static PrintStream sysout = System.out;
static int caseNum;
private static void solve() throws IOException
{
PreCompute();
int C = in.nextInt();
for (int i = 0; i < C; i++) {
caseNum = i + 1;
out.print("Case #" + caseNum + ": ");
solveCase();
}
}
private static void PreCompute() {
}
private static void solveCase() throws IOException {
int N = in.nextInt();
int[] A = new int[N];
int[] B = new int[N];
int ans = 0;
HashMap<Integer, Integer> pair = new HashMap<>();
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
B[i] = in.nextInt();
pair.put(A[i], B[i]);
}
Arrays.sort(A);
for (int i = 0; i < N; i++) {
int b = pair.get(A[i]);
for (int j = i + 1; j < N; j++) {
if (pair.get(A[j]) < b)
ans++;
}
}
out.println(ans);
}
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean usingFileForIO = true;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("E:\\zin.txt");
out = new PrintStream("E:\\zout.txt");
}
else {
in = new MyScanner();
out = System.out;
}
solve();
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
public String nextLine() throws IOException {
return inp.nextLine();
}
}
}
No comments:
Post a Comment