题目描述:现有n个物品,每个物品有三个参数ai,bi,ci,定义i物品不合格品的依据是:若存在物品j,且aj>ai, bj>bi, cj > ci,则称i物品为不合格品。
全题如图:
解决思路:
- 思路很简单,一个一个比较,但是注意for循环中,第二个for循环的下标。j始终是从0开始的,说明每个i都会和j比较,一旦i不合格,不用删去,因为i是递增的。
import java.util.Scanner;
public class Main {
static class Good{
public int a;
public int b;
public int c;
public Good(int a, int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
}
private static boolean fun(int idx,int[][] a ) {
for (int i = 0;i < a.length; i++) {
if (a[idx][0]<a[i][0]&&a[idx][1]<a[i][1]&&a[idx][2]<a[i][2]) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
Good[] goods = new Good[N];
for (int i = 0; i < N; i++) {
goods[i] = new Good(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
}
int count=0;
for (int i = 0; i < N; i++) {
for(int j = 0; j < N; j++){
if(goods[i].a < goods[j].a && goods[i].b < goods[j].b && goods[i].c < goods[j].c){
count++;
break;
}
}
}
System.out.println(count);
}
}
网友评论