记录编号 415129 评测结果 AAAAAAAAAA
题目名称 [JSOI 2008]球形空间产生器sphere 最终得分 100
用户昵称 GravatarHallmeow 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2017-06-15 16:59:41 内存使用 0.00 MiB
显示代码纯文本
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
#define pos2(i,a,b) for(int i=(a);i>=(b);i--)
#define N 60
using namespace std;
int n;
double a[N][N],b[N],x[N];
int flag;
void swap(double &xx,double &yy)
{
     double temp;
     temp=xx;
     xx=yy;
     yy=temp;
}
int gauss()
{
    double t;
    int im,num=1;
    for(int k=1;k<n;k++,num++)
    {
        im=k;
        pos(i,k+1,n)
           if(fabs(a[i][k])>fabs(a[im][k]))
             im=i;
        if(im!=k)
        {
           pos(i,k,n)
             swap(a[num][i],a[im][i]);
           swap(b[num],b[im]);      
        }
        if(!a[num][k])
        {
           num--;
           continue;
        }
        pos(i,num+1,n)
        {
           if(!a[num][k])
             continue;
           t=a[i][k]/a[num][k];
           pos(j,k,n+1)
              a[i][j]-=t*a[k][j];
           b[i]-=t*b[k];
        }
    }
    pos(i,num,n)
      if(!a[i][n]&&b[i])
        return -1;
    pos2(i,n,1)
    {
       pos2(j,n,i+1)
         b[i]-=a[i][j]*x[j];
       if(!a[i][i]&&b[i]!=0)
         return -1;
       if(!a[i][i]&&!b[i])
         return 0;
       x[i]=b[i]/a[i][i];
    }
    return 1;
}
double cun[N][N];
int haha()
{
    freopen("bzoj_1013.in","r",stdin);
    freopen("bzoj_1013.out","w",stdout); 
    scanf("%d",&n);
    pos(i,1,n+1)
      pos(j,1,n)
       scanf("%lf",&cun[i][j]);         
    pos(i,1,n)      
    {   
        pos(j,1,n)
        {
           a[j][i]=2*(cun[j+1][i]-cun[j][i]);       
        }
        pos(j,1,n)
        {
          b[i]+=cun[i+1][j]*cun[i+1][j]-cun[i][j]*cun[i][j];
          //scanf("%lf",&b[i]);
        }
    }
    flag=gauss();
    if(flag!=1)
      printf("%d",flag);
    else
       pos(i,1,n)
           printf("%0.3lf ",x[i]);
    //while(1);
    return 0;
}
int sb=haha();
int main()
{;}