编程题:
1.
public static Boolean metrix(int [] metrix,int n) {
int count = 0;
int maxCondition = 0;
boolean firstForEachWithNoAppOne = true;
for (int number : metrix) {
if(number == 1) {
if(firstForEachWithNoAppOne == true) {
if(count >= 2) {
maxCondition += (count/2);
}
firstForEachWithNoAppOne = false;
count = 0;
}
if(count >= 3 && firstForEachWithNoAppOne == false) {
if(count % 2 == 1) {
maxCondition += (count/2);
}else {
maxCondition += (count/2 - 1);
}
}
count = 0;
}else {
count ++;
}
}
if(count >= 2) {
maxCondition += (count/2 );
}
return n <= maxCondition ? true : false;
}
2. 91种
public static int Comp() {
int count = 0;
for(int i = 0 ; i <= 30 ; i ++) {
for(int j = 0 ; j <= 20 ; j++) {
for(int k = 0 ; k <= 10 ; k ++) {
if(i*10 + j*20 + k*30 == 300) {
count ++;
System.out.println("十公里: " + i +" 二十公里: "+j + "三十公里: " +k);
break;
}
if(i*10 + j*20 + k*30 > 300) {
break;
}
}
}
}
return count;
}