题目:
输入输出样例
输入:
10
56 12 1 99 1000 234 33 55 99 812
输出:
3 2 7 8 1 4 9 6 10 5
291.90
思路:贪心,注意细节
代码
package 贪心;
import java.util.Arrays;
import java.util.Scanner;
public class P1223排队接水 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double[] a=new double[n];
double[] b=new double[n];
int[] c=new int[n];//判断是否已经输出
for (int i = 0; i < n; i++) {
a[i]=sc.nextInt();
b[i]=a[i];
}
Arrays.sort(a);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i]==b[j]&&c[j]==0){
if (i==n-1)
System.out.println(j+1);
else
System.out.print(j+1+" ");
c[j]=1;
//break;//去重防止运算过大(可以不加)
}
}
}
double sum=0;
double h=n-1;
for (int i = 0; i < n; i++) {
sum+=a[i]*(h--);//计算总的时间和
}
System.out.println(String.format("%.2f",sum/n));
}
}