package qe;
public class Ac {
public static int greedySelector(int[] s, int[] f, boolean[] a) {
int n = s.length - 1;
a[1] = true;
int j = 1;
int count = 1;
for (int i = 2; i <= n; i++) {
if (s[i] >= f[j]) {
a[i] = true;
j = i;
count++;
} else {
a[i] = false;
}
}
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] s = { 13,23,22,12,5,8,6,9,11,15,43 };
int[] f = { 8, 23, 6, 7, 4, 9, 11, 22, 12, 5,43};
boolean[] a = new boolean[s.length];
int result = greedySelector(s, f, a);
System.out.println("Result is: " + result);
for (int i = 1; i <= s.length - 1; i++) {
if (a[i]) {
System.out.println("第" + i + "活动被选中,其开始时间为:" + s[i] + ",结束时间为:" + f[i]);
}
}
}
}
在这里插入代码片