absi2011's Blog & Daily Life.

全新的开始       我要省选翻盘       I wanna AK in 高考\化学       自此,生无可恋
[破碎的状态] [-4] POJ 2536
[破碎的状态] [-4] Hdu 2586

[破碎的状态] [-4] BZOJ 1013

absi2011 posted @ Jul 18, 2016 09:23:04 PM in 刷题记录 with tags bzoj 小高考 高斯消元 , 648 阅读

一个高斯消元的好题...感谢@JCarlson 带我找题

设目标点的坐标,套公式,得到n+1个方程

n+1个方程减一下,得到n个一元一次方程

高斯消元可解

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
double c[15][15];
double a[15][15];
double b[15];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%lf",&c[n][i]);
    }
    for (i=0;i<n;i++)
    {
        int j;
        for (j=0;j<n;j++)
        {
            scanf("%lf",&c[i][j]);
            a[i][j]=2*c[i][j]-2*c[n][j];
            b[i]+=c[i][j]*c[i][j]-c[n][j]*c[n][j];
        }
    }
    for (i=0;i<n;i++)
    {
        int j;
        for (j=i;j<n;j++)
        {
            if (a[i][i]!=0) break;
        }
        int k;
        for (k=0;k<n;k++)
        {
            swap(a[i][k],a[j][k]);
        }
        for (j=i+1;j<n;j++)
        {
            for (k=i+1;k<n;k++)
            {
                a[j][k]-=a[i][k]*a[j][i]/a[i][i];
            }
            b[j]-=b[i]*a[j][i]/a[i][i];
            a[j][i]=0;
        }
    }
    for (i=n-1;i>=0;i--)
    {
        b[i]/=a[i][i];
        a[i][i]=1;
        int j;
        for (j=0;j<i;j++)
        {
            b[j]-=b[i]*a[j][i];
            a[j][i]=0;
        }
    }
    for (i=0;i<n-1;i++)
    {
        printf("%.3lf ",b[i]);
    }
    if (i==n-1) printf("%.3lf\n",b[i]);
    return 0;
}
pavzi.com 说:
Jan 27, 2024 05:36:39 PM

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter