QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582770 | #6620. Linear Fractional Transformation | stavage | WA | 124ms | 3920kb | C++17 | 2.3kb | 2024-09-22 17:25:02 | 2024-09-22 17:25:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define int LL
#define double LD
typedef pair<int, int> PII;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int inf = 0x3f3f3f3f3f3f3f3f;
const double PI = acosl(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;
int n;
double a[110][110];
int gauss()
{
int r, c;//行,列
for (c = 1, r = 1; c <= n; c++) {
int t = r;
for (int i = r; i <= n; i++) {
if (fabs(a[i][c]) > fabs(a[t][c])) t = i;
}
if (fabs(a[t][c]) < eps) continue;//用于下面判断解的情况
for (int i = c; i <= n + 1; i++) swap(a[t][i], a[r][i]);
for (int i = n + 1; i >= c; i--) a[r][i] /= a[r][c];
for (int i = r + 1; i <= n; i++) {
if (fabs(a[i][c]) > eps) {
for (int j = n + 1; j >= c; j--) a[i][j] -= a[r][j] * a[i][c];//目的为了把第r的第c个数变为0
}
}
r++;
}
if (r <= n) {
for (int i = r; i <= n; i++) {
if (fabs(a[i][n + 1]) > eps) return 2;//无解,出现0 = b情况
}
return 1;//无穷多解
}
for (int i = n; i >= 1; i--) {
for (int j = i + 1; j <= n; j++) a[i][n + 1] -= a[i][j] * a[j][n + 1];
}
return 0;//有单组解
}
/*
for (int i = 1; i <= n; i++) {
printf("%.2lf\n", a[i][n + 1]);
}
*/
int p[10], q[10], r[10], s[10];
void solve()
{
for (int i = 1; i <= 3; i++) {
cin >> p[i] >> q[i] >> r[i] >> s[i];
}
if (p[1] == 0 && q[1] == 0) {
p[1] = p[3];
q[1] = q[3];
r[1] = r[3];
s[1] = s[3];
}
else if (p[2] == 0 && q[2] == 0) {
p[2] = p[3];
q[2] = q[3];
r[2] = r[3];
s[2] = s[3];
}
cin >> p[0] >> q[0];
n = 2;
a[1][1] = p[1], a[1][2] = p[2], a[1][3] = p[0];
a[2][1] = q[1], a[2][2] = q[2], a[2][3] = q[0];
gauss();
double ans1, ans2;
ans1 = r[1] * a[1][3] + r[2] * a[2][3];
ans2 = s[1] * a[1][3] + s[2] * a[2][3];
cout << ans1 << " " << ans2 << "\n";
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(15);
int _;
cin >> _;
// _ = 1;
while (_--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3900kb
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.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000
result:
ok 4 numbers
Test #2:
score: -100
Wrong Answer
time: 124ms
memory: 3920kb
input:
100000 0 0 -1 1 1 1 1 0 1 0 1 -1 -1 0 -1 -1 -1 1 1 -1 1 -1 -1 0 1 0 -1 -1 -1 -1 0 -1 -1 1 -1 -1 0 -1 0 0 1 1 1 0 0 -1 0 0 0 0 -1 -1 1 0 1 1 -1 -1 0 -1 0 1 1 -1 1 0 -1 -1 1 -1 0 1 1 -1 1 0 1 0 0 -1 0 1 -1 -1 1 1 -1 1 0 0 -1 -1 0 1 0 1 1 0 1 1 1 -1 0 1 -1 -1 1 0 -1 0 1 -1 1 0 -1 1 -1 -1 1 0 0 -1 0 1 0...
output:
-1.000000000000000 1.000000000000000 -1.000000000000000 1.000000000000000 -0.000000000000000 1.000000000000000 -1.000000000000000 -0.000000000000000 -2.000000000000000 3.000000000000000 -2.000000000000000 1.000000000000000 -1.000000000000000 0.000000000000000 3.000000000000000 1.000000000000000 0.00...
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '-1.0000000', error = '2.0000000'