zoukankan      html  css  js  c++  java
  • ZOJ 3645 BiliBili(高斯消元)

    Shirai Kuroko is a Senior One student. Almost everyone in Academy City have super powers, and Kuroko is good at using it. Her ability is "Teleporting", which can make people to transfer in the eleven dimension, and it shows like moving instantly in general people's eyes.

    Railgun_Kuroko.jpg

    In fact, the theory of the ability is simple. Each time, Kuroko will calculate the distance between some known objects and the destination in the eleven dimension so that Kuroko can get the coordinate of the destination where she want to go and use her ability.

    Now we have known that the coordinate of twelve objects in the eleven dimension Vi = (Xi1,Xi2, ... ,Xi11), and 1 <= i <= 12. We also known that the distance Di between the destination and the object. Please write a program to calculate the coordinate of the destination. We can assume that the answer is unique and any four of the twelve objects are not on the same planar.

    Input

    The first line contains an integer T, means there are T test cases. For each test case, there are twelve lines, each line contains twelve real numbers, which means Xi1,Xi2, ... ,Xi11and DiT is less than 100.

    Output

    For each test case, you need to output eleven real numbers, which shows the coordinate of the destination. Round to 2 decimal places.

    题目大意:11维度上有一个未知的点,现在已知12个点的坐标和他们到这个未知的点的距离,求这个未知的点的坐标。

    思路:设未知的点为(p1, p2, ……, pn)

    那么对于每个已知点,列方程(xi1 - p1)^2 + (xi2 - p2)^2 + …… + (xin - pn)^2 = Di^2

    然后,对于前11个方程,减去第12个方程,就能得到一个线性方程组。

    然后高斯消元解即可。

    PS:我的代码不加那个EPS会跪,我觉得以后没事还是把它加上吧……

    代码(0MS):

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cmath>
     6 using namespace std;
     7 
     8 const double EPS = 1e-12;
     9 const int MAXN = 15;
    10 
    11 double mat[MAXN][MAXN];
    12 int n = 11, T;
    13 
    14 inline int sgn(double x) {
    15     return (x > EPS) - (x < -EPS);
    16 }
    17 
    18 void guess_eliminatioin() {
    19     for(int i = 0; i < n; ++i) {
    20         int r = i;
    21         for(int j = i + 1; j < n; ++j)
    22             if(fabs(mat[j][i]) > fabs(mat[r][i])) r = j;
    23         if(sgn(mat[r][i]) == 0) continue;
    24         if(r != i) for(int j = 0; j <= n; ++j) swap(mat[r][j], mat[i][j]);
    25         for(int j = n; j >= i; --j)
    26             for(int k = i + 1; k < n; ++k) mat[k][j] -= mat[k][i] / mat[i][i] * mat[i][j];
    27     }
    28     for(int i = n - 1; i >= 0; --i) {
    29         for(int j = i + 1; j < n; ++j)
    30             mat[i][n] -= mat[j][n] * mat[i][j];
    31         mat[i][n] /= mat[i][i];
    32     }
    33 }
    34 
    35 int main() {
    36     scanf("%d", &T);
    37     while(T--) {
    38         for(int i = 0; i <= n; ++i)
    39             for(int j = 0; j <= n; ++j) scanf("%lf", &mat[i][j]);
    40         for(int i = 0; i < n; ++i) {
    41             mat[i][n] = mat[i][n] * mat[i][n] - mat[n][n] * mat[n][n];
    42             for(int j = 0; j < n; ++j) {
    43                 mat[i][n] -= mat[i][j] * mat[i][j] - mat[n][j] * mat[n][j];
    44                 mat[i][j] = -2 * mat[i][j] + 2 * mat[n][j];
    45             }
    46         }
    47         guess_eliminatioin();
    48         for(int i = 0; i < n - 1; ++i) printf("%.2f ", mat[i][n] + EPS);
    49         printf("%.2f
    ", mat[n - 1][n] + EPS);
    50     }
    51 }
    View Code
  • 相关阅读:
    swagger Unable to render this definition
    企业应用向ASP.NET Core迁移
    .NET Core EF框架使用SQL server 2008数据库分页问题:Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement
    .NET Core应用中使用分布式缓存及内存缓存
    .NET Core Session的使用方法
    .NET Core 2.1中的HttpClientFactory最佳实践
    转载:ZooKeeper Programmer's Guide(中文翻译)
    Python【map、reduce、filter】内置函数使用说明(转载)
    Python使用基础
    Redis Sentinel:集群Failover解决方案(转载)
  • 原文地址:https://www.cnblogs.com/oyking/p/3613312.html
Copyright © 2011-2022 走看看