1 条题解

  • 0
    @ 2024-3-30 20:39:32
    #include<cstdio>
    #include<algorithm>
    #define Abs(x) (x) < 0 ? -(x) : (x)
    
    using namespace std;
    
    int n;
    double a[12][11], fc[12][12];
    
    void gaosi() {//高斯消元
    	for (int i = 1; i <= n; i++) {
    		int maxx = i;
    		for (int j = i + 1; j <= n; j++)
    			if (Abs(fc[j][i]) > Abs(fc[maxx][i]))
    				maxx = j;
    		for (int j = 1; j <= n + 1; j++)
    			swap(fc[i][j], fc[maxx][j]);
    		for (int j = 1; j <= n; j++)
    			if (i != j)
    				for (int k = i + 1; k <= n + 1; k++)
    					fc[j][k] = fc[j][k] - (fc[i][k] * (fc[j][i] / fc[i][i]));
    	}
    }
    
    int main() {
    	scanf("%d", &n);//读入
    	for (int i = 1; i <= n + 1; i++)
    		for (int j = 1; j <= n; j++)
    			scanf("%lf", &a[i][j]);//读入
    	
    	for (int i = 1; i <= n; i++)
    		for (int j = 1; j <= n; j++) {//求出方程式
    			fc[i][j] = 2 * (a[i][j] - a[i + 1][j]);
    			fc[i][n + 1] += a[i][j] * a[i][j] - a[i + 1][j] * a[i + 1][j];
    		}
    	
    	gaosi();//高斯消元
    	
    	for (int i = 1; i <= n; i++)
    		printf("%.3lf ", fc[i][n + 1] / fc[i][i]);//输出
    	
    	return 0;
    }
    
    
  • 1

信息

ID
118
时间
1000ms
内存
128MiB
难度
8
标签
递交数
13
已通过
8
上传者