QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#636440#6620. Linear Fractional Transformationjty233WA 0ms3868kbC++233.6kb2024-10-12 23:54:382024-10-12 23:54:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 23:54:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-10-12 23:54:38]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
using i64 = long long;

template<size_t N, size_t M>
struct Matrix{
    const double eps = 1e-9;
    int n, m;
    double val[N][M];
    Matrix(int n, int m){
        this -> n = n;
        this -> m = m;
        memset(val, 0, sizeof(val));
    }
    Matrix() : Matrix(N, M){}
    double* operator [](int x){
        return val[x];
    }

    void print(){
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                cout << val[i][j] << ' ';
            }
            cout << "&\n";
        }
    }

    void swap(double &x, double &y){
        double temp = x;
        x = y;
        y = temp;
    }

    void swapLine(int x, int y){
        for(int i = 0; i < m; i++) swap(val[x][i], val[y][i]);
    }

    bool GE(void){
        // if(n != m - 1) return false;
        for(int i = 0; i < m-1; i++){
            int maxArg = i;
            for(int j = i + 1; j < n; j++)
                if(std::abs(val[j][i]) > std::abs(val[maxArg][i])) maxArg = j;
            swapLine(maxArg, i);
            if(std::abs(val[i][i]) < eps) return false;
            for(int j = 0; j < n; j++){
                if(i == j) continue;
                double c = val[j][i] / val[i][i];
                for(int k = i; k < m; k++) val[j][k] -= val[i][k] * c;
            }
        }
        for(int i = 0; i < n; i++) val[i][m-1] /= val[i][i], val[i][i] = 1.0;
        return true;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(10);

    int T; cin >> T;
    while(T--){
        Matrix<6, 7> mx;
        Matrix<6, 5> mx2;
        auto read = [&](int row){
            double x, y, w1, w2;
            cin >> x >> y >> w1 >> w2;

            mx[row][0] = x;     // a1
            mx[row][1] = -y;    // a2
            mx[row][2] = 1;     // c1
            mx[row][3] = 0;     // c2
            mx[row][4] = -w1;   // d1
            mx[row][5] = w2;    // d2
            mx[row][6] = -w2*y + w1*x;

            mx2[row][0] = x;
            mx2[row][1] = -y;
            mx2[row][2] = 1;
            mx2[row][3] = 0;
            mx2[row][4] = w1;

            row++;

            mx[row][0] = y;     // a1
            mx[row][1] = x;     // a2
            mx[row][2] = 0;     // c1
            mx[row][3] = 1;     // c2
            mx[row][4] = -w2;   // d1
            mx[row][5] = -w1;   // d2
            mx[row][6] = w1*y + w2*x;

            mx2[row][0] = y;
            mx2[row][1] = x;
            mx2[row][2] = 0;
            mx2[row][3] = 1;
            mx2[row][4] = w2;
        };
        read(0); read(2); read(4);

        double x, y; cin >> x >> y;
        // mx.print();
        if(mx.GE()){
            auto a1 = mx[0][6];
            auto a2 = mx[1][6];
            auto c1 = mx[2][6];
            auto c2 = mx[3][6];
            auto d1 = mx[4][6];
            auto d2 = mx[5][6];

            // printf("%lf %lf %lf %lf %lf %lf\n", a1, a2, c1, c2, d1, d2);
            
            double div = (x+d1)*(x+d1) + (y+d2)*(y+d2);

            cout << ((a1*x-a2*y+c1)*(x+d1) + (a2*x+a1*y+c2)*(y+d2)) / div << ' ';
            cout << ((a2*x+a1*y+c2)*(x+d1) - (a1*x-a2*y+c1)*(y+d2)) / div << '\n';
        }else{
            mx2.GE();
            auto a1 = mx2[0][4];
            auto a2 = mx2[1][4];
            auto c1 = mx2[2][4];
            auto c2 = mx2[3][4];

            // printf("%lf %lf %lf %lf\n", a1, a2, c1, c2);

            cout << (a1*x-a2*y+c1) << ' ';
            cout << (a1*y+a2*x+c2) << '\n';
        }
    }

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3868kb

input:

2
-1 0 0 -1
0 1 -1 0
1 0 0 1
0 -1
-1 0 -1 0
0 1 0 -1
1 0 1 0
0 -1

output:

-1.0000000000 0.0000000000
0.0000000000 1.0000000000

result:

wrong answer 1st numbers differ - expected: '1.0000000', found: '-1.0000000', error = '2.0000000'