赞
踩
要点:解决问题方法的效率,跟算法的巧妙程度有关
思考:如何让算法更巧妙
参考:实现多项式的两种算法
public static double f1(int n,double[] a,double x) { double rs=a[0]; for (int i = 1; i < a.length; i++) { rs+=a[i]*Math.pow(x, i); } return rs; } public static double f2(int n,double[] a,double x) { double rs=a[n]; for (int i = n; i >0; i--) { rs=a[i-1]+rs*x; } return rs; }
public static double f1(int n,double[] a,double x) {
double rs=a[0];
for (int i = 1; i < a.length; i++) {
rs+=a[i]*Math.pow(x, i);
}
return rs;
}
public static double f2(int n,double[] a,double x) {
double rs=a[n];
for (int i = n; i >0; i--) {
rs=a[i-1]+rs*x;
}
return rs;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。