package 套娃问题;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;
class Node {
public int w;
public int h;
public int getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
public Node() {
super();
// TODO 自动生成的构造函数存根
}
public Node(int w, int h) {
super();
this.w = w;
this.h = h;
}
}
public class Test {
public static Comparator<Node> idComparator = new Comparator<Node>() {
public int compare(Node o1, Node o2) {
// TODO 自动生成的方法存根
if ((o1.w - o2.w) > 0 || (o1.h - o2.h) > 0) {
return 1;
}
if ((o1.w - o2.w) < 0 || (o1.h - o2.h) < 0) {
return -1;
}
return 0;
}
};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入一个数字:");
int num = in.nextInt();
while (num < 1 || num > 50) {
System.out.println("输入的数字超出约定范围请重新输入:");
num = in.nextInt();
}
int i = 1;
LinkedList<Node> list = new LinkedList<Node>();
while (i <= num) {
System.out.println("输入成对数字: ");
int w = in.nextInt();
int h = in.nextInt();
Node node = new Node(w, h);
list.add(node);
i++;
}
Collections.sort(list,idComparator);
int total=0;
int t1=Integer.MIN_VALUE;
int t2=Integer.MIN_VALUE;
// 遍历
while(!list.isEmpty()){
Node node=list.removeFirst();
if(t1<node.w && t2<node.h){
t1=node.w;
t2=node.h;
total++;
}
}
if(list.size()==0){
System.out.println(0);
}else{
System.out.println(total);
}
}
}
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;
class Node {
public int w;
public int h;
public int getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
public Node() {
super();
// TODO 自动生成的构造函数存根
}
public Node(int w, int h) {
super();
this.w = w;
this.h = h;
}
}
public class Test {
public static Comparator<Node> idComparator = new Comparator<Node>() {
public int compare(Node o1, Node o2) {
// TODO 自动生成的方法存根
if ((o1.w - o2.w) > 0 || (o1.h - o2.h) > 0) {
return 1;
}
if ((o1.w - o2.w) < 0 || (o1.h - o2.h) < 0) {
return -1;
}
return 0;
}
};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入一个数字:");
int num = in.nextInt();
while (num < 1 || num > 50) {
System.out.println("输入的数字超出约定范围请重新输入:");
num = in.nextInt();
}
int i = 1;
LinkedList<Node> list = new LinkedList<Node>();
while (i <= num) {
System.out.println("输入成对数字: ");
int w = in.nextInt();
int h = in.nextInt();
Node node = new Node(w, h);
list.add(node);
i++;
}
Collections.sort(list,idComparator);
int total=0;
int t1=Integer.MIN_VALUE;
int t2=Integer.MIN_VALUE;
// 遍历
while(!list.isEmpty()){
Node node=list.removeFirst();
if(t1<node.w && t2<node.h){
t1=node.w;
t2=node.h;
total++;
}
}
if(list.size()==0){
System.out.println(0);
}else{
System.out.println(total);
}
}
}