
import java.util.ArrayList;
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()) {
int n=sc.nextInt();
sc.nextLine();
String[] s=sc.nextLine().split(" ");
long[] arr=new long[n];
for (int i = 0; i < s.length; i++) {
arr[i]=Long.valueOf(s[i]);
}
int res = moveBicycle(n, arr);
System.out.println("移动车的数量:"+res);
}
}
/**
* @param n 车的数量
* @param m 车停放的位置
* @return 移动车的最少数量
*/
public static int moveBicycle(int n,long[] m) {
int count=0;
int gap=0;
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<Long> list2 = new ArrayList<Long>();
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
int k =(int)(m[j]-m[i])/(j-i);
int tempCount=0;
for (int h = 0; h < n; h++) {
if(m[h]-m[i]==k*(h-i)){
tempCount++;
}
}
if(tempCount > count){
count =tempCount ;
gap=k;
list.clear();
list2.clear();
for (int h = 0; h < n; h++) {
list2.add(m[h]);
if(m[h]-m[i]!=k*(h-i)){
list.add(h+1);
list2.set(h,k*(h-i)+m[i]);
}
}
}
}
}
System.out.println("移动后每辆车间距为:"+ gap);
System.out.println("移动车的下标为(第1辆车记下标为1):"+ list);
System.out.println("移动后车的顺序为:");
System.out.println(list2);
return n-count;
}
}
4
1 3 6 7
移动后每辆车间距为:2
移动车的下标为(第1辆车记下标为1):[3]
移动后车的顺序为:
[1, 3, 5, 7]
移动车的数量:1