最佳拟合直线
来源:互联网 发布:java在线 编辑:程序博客网 时间:2024/04/30 05:14
import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner cin = new Scanner(System.in);while (cin.hasNext()) {int n = cin.nextInt(); int[] x=new int[n]; int[] y=new int[n];for (int i = 0; i < n; i++) { x[i]=cin.nextInt(); y[i]=cin.nextInt();}int fx=sum(x);int fy=sum(y);int fxy=sum(x,y);int fxx=sum(x,x);double a=(double)(n*fxy-fx*fy)/(n*fxx-fx*fx);double b=(double)(fy*fxx-fx*fxy)/(n*fxx-fx*fx);System.out.println(String.format("%.3f",a));System.out.println(String.format("%.3f",b));}cin.close();}public static int sum(int[]... arr){int len=arr.length ;int deeplen=arr[0].length;@SuppressWarnings("unused")int sum=0;for(int i=0;i<deeplen;i++){if(len==1){sum+=arr[0][i];}else if(len==2){sum+=arr[0][i]*arr[1][i];}}return sum;}}
0 0
- hdu2728 最佳拟合直线
- 最佳拟合直线
- 最佳拟合直线
- sdut_java_最佳拟合直线
- 最佳拟合直线
- 最佳拟合直线
- Java sdut acm 2728 最佳拟合直线
- 直线拟合
- 直线拟合
- 直线拟合
- 最小二乘法直线拟合、圆拟合
- 2014寒假ACM集训13级PK赛-最佳拟合直线
- 回归算法学习笔记(一)用线性回归线找到最佳拟合直线
- 使用线性回归拟合平面最佳直线及预测之Python+sklearn实现
- 使用线性回归拟合平面最佳直线及预测之Python+sklearn实现
- 最小二乘法直线拟合
- 最小二乘法直线拟合
- 最小二乘法直线拟合
- Linux关机命令
- Node.js 获取客户端IP, 以及nginx转发携带客户端ip配置
- Android cannot allocate memory
- (ITEXT)PDF上空白区域加入数据
- qscoj 喵哈哈村与哗啦啦村的大战(四)(树形DP求非严格路径数量)
- 最佳拟合直线
- 如何建立高效的测试团队
- JAVA线程池原理以及几种线程池类型介绍
- 下拉框的value值和text值的操作方法
- Java中常量Map、常量List
- 用jQuery得到form表单里面文本框、密码框、单选框、下拉框、复选框的值
- 史上最全的Android studio 的快捷键 MAC 和Win版本
- 【模板篇】伸展树Splay Tree(此坑待填)
- SuperMap 平台中三维模型的常见问题及解决办法