poj 1065 Wooden Sticks
2011/08/28
java
pku
poj
自力でない
Javaです。POJです。
1065 -- Wooden Sticks
これも自力でないです。
いろいろ参考にしましたが、よく理解できてないです。
PKU 1065 Wooden Sticks - 敗戦記
package p1065_not_completed;
import java.io.IOException;
import java.util.Scanner;
public class Main {
static boolean debug = false;
static class Pair {
int w;
int l;
boolean use = false;
public Pair(int l, int w) {
this.w = w;
this.l = l;
}
public String toString() {
return "l:[" + l + "] w:[" + w + "] use:[" + use + "]";
}
}
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int setupTime = 0;
int n = scanner.nextInt();
Pair[] pairs = new Pair[n];
for (int j = 0; j < n; j++) {
int l = scanner.nextInt();
int w = scanner.nextInt();
Pair pair = new Pair(l, w);
pairs[j] = pair;
}
sort(pairs);
print(pairs);
setupTime = count(pairs);
System.out.println(setupTime);
}
}
static void print(Pair[] pairs) {
if (!debug)
return;
for (Pair pair : pairs) {
System.err.println(pair);
}
System.err.println();
}
static void sort(Pair[] pairs) {
for (int i = 0; i < pairs.length; i++) {
print(pairs);
for (int k = i + 1; k < pairs.length; k++) {
if (pairs[i].l < pairs[k].l) {
Pair pair = pairs[i];
pairs[i] = pairs[k];
pairs[k] = pair;
}
}
}
}
static int count(Pair[] pairs) {
int c = 0;
for (int i = 0; i < pairs.length; i++) {
Pair p1 = pairs[i];
if (p1.use)
continue;
for (int j = i + 1; j < pairs.length; j++) {
Pair p2 = pairs[j];
if (p2.use)
continue;
if ((p2.l <= p1.l && p2.w <= p1.w)) {
p2.use = true;
p1 = p2;
}
}
c++;
}
return c;
}
}
: